Existing database - new project

52 views
Skip to first unread message

Robert Daniels

unread,
Mar 6, 2015, 4:39:33 PM3/6/15
to django...@googlegroups.com
I understand it is possible to use an existing database on a new Django project.

As I see it, I have 2 choices.

1 - Use the existing database and deal with it in that fashion.

or

2 - Create a new project to store the same type of data as if there were no existing database, Then write a separate export-import script to move the data from the existing db to the new structure.

Wondering if anyone has gone through the "good" and "bad" of each of these. I have about 100,000 records in the database, but moving the data across should not be that difficult as its a pretty flat model

john

unread,
Mar 6, 2015, 6:42:31 PM3/6/15
to django...@googlegroups.com
I'm not sure this is of help but I took was the easy way out. In my
models.py for each of my models.Model I added
Class Meta:
managed = False

That worked for me - the existing database tables were not touched.

Johnf

Derek

unread,
Mar 7, 2015, 9:31:24 AM3/7/15
to django...@googlegroups.com
I have taken route 1 before; its a bit more messy because you may have to explicitly map your desired model names to the actual column names.  You also face the issue of dealing with primary keys.

If you have the choice, and the current database is not in use anymore, I would create a new one, using Django conventions (such as an auto-increment primary key, with "unique_together" constraints) and then import the existing data.  This has the added benefit of allowing you to validate the existing data and ensure that you start with a 'clean' data set.

HTH
Derek

Collin Anderson

unread,
Mar 10, 2015, 1:03:21 PM3/10/15
to django...@googlegroups.com
Hi,

inspectdb makes step #1 much easier.

If you're not planning on removing some of the columns or restructuring things, I'd recommend #1.

Collin 

Robert Daniels

unread,
Mar 13, 2015, 2:36:56 PM3/13/15
to django...@googlegroups.com

thanks for everyone's input. I'll run parallel implementations and see which one works best for the long haul.

Reply all
Reply to author
Forward
0 new messages