0

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?

Community
  • 1
  • 1
Samudra
  • 1,013
  • 1
  • 14
  • 21
  • 1
    Possible duplicate http://stackoverflow.com/questions/175993/what-is-the-best-way-to-migrate-data-in-django. – Pramod Jun 02 '12 at 16:23
  • @Pramod It does look like it, but those answers are from 4 years ago. Could it be that there is a better/easier solution now? – Samudra Jun 02 '12 at 16:32
  • I don't think so. I've used South and it has worked well for me. – Pramod Jun 02 '12 at 16:36

2 Answers2

2

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;
ptoal
  • 101
  • 4
  • would you mind sharing your fabfile? I am new to Python, would be a good learning point. Also, a question about Fab: would the same commands work in Windows shell as well as Linux shell? Or have I misunderstood its use? – Samudra Jun 02 '12 at 18:57
  • Alas, my fabfile has grown rather organically, and is a little untidy. Not much use for anyone but the creator. I just discovered a [django-fabdeploy-plus](http://pypi.python.org/pypi/django-fabdeploy-plus/0.4) project that might be helpful to you, though. – ptoal Jun 02 '12 at 21:46
  • I think I will go with South. Seems hassle-free to me :) – Samudra Jun 02 '12 at 23:25
0

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

ajwood
  • 18,227
  • 15
  • 61
  • 104
  • I could not find this in the Django docs... is this supported in 1.4? – Samudra Jun 02 '12 at 19:05
  • I'm using it in 1.3. You're right that it disappeared from the 1.4 docs though... you could try `python manage.py` which lists the supported commands. In 1.3, `reset ` drops and creates tables for the specified apps(s) – ajwood Jun 03 '12 at 13:02