Question

I'm in the initial phase of development, and the models are changing around quite a lot.
I have to keep dropping the old tables and then performing a "syncdb"

While I appreciate the reason why syncdb does not alter the old tables,

Is it possible (or is there any other alternative) to drop the old tables automatically and then run syncdb?

Was it helpful?

Solution

They way I typically do this is at the database level. If, for example, you were using postgres, and just wanted to blow away the whole DB to start fresh, you could do:

dropdb -U postgres "dbname"
createdb -U postgres -O "db_user" "db_name"

For long projects I'm working on, I use a fabfile for automating tasks like the above, as well as grabbing the latest database from my production server, and overwriting my local development db.

Also, related is database "migration", which becomes a requirement when you change code after it's been running in production a while. A lot of people / apps use South, but I prefer Nashvegas for my sites.

With Nashvegas, I would create a 0001_add_field_blah.sql file which contained my raw SQL commands for altering the db. eg:

ALTER TABLE myapp_model RENAME COLUMN first_name TO given_name;

OTHER TIPS

I use python manage.py reset <app>. I don't think there's a way to do it project-wide though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top