Posts Tagged ‘django settings’

Integrating Django with a legacy database

August 1, 2014 Leave a comment

After connect to your database.

Step 1:

python inspectdb

Outputs general models from your db that u defined it in settings file.

Step 2:

python inspectdb > ./your_app/

creates file from the output in *nix systems.

Step 3:

You’ll have to do the following manually to clean this up:

Rearrange models order

Make sure each model has one field with primary_key=True

Remove ‘managed = False’ lines if you wish to allow Django to create and delete the table

Step 4:

But it will have some problems like same table will more than one foreign key fields, those filed names should not have the related_name because with out related_name you django can’t figure out which field is connects to foreign key filed. To check this run the following command.

You will see the sqlcustom [appname] but dont run this command because it wont take the

python sqlcustom [appname]





%d bloggers like this: