views:

248

answers:

4

Recently I have been trying to learn web development in Django and i am very happy about it...

But, one thing is really annoying -especially when you get the idea about 'simplicity' philosophy behind django.

It is that updating a table in django is really far away from simplicity as i just experienced.

For example, just like the real case I had, I skipped adding a slug field for entry titles in the beginning. But after a while, I wanted to add a slug column in the table, just like everyone -who is a rookie in django may expect, I tried python manage.py syncdb command. And of course it didn't work... After a bit search I found "I need to add a new column 'manually' in the dbshell command line" (the database i am using is mysql).

I don't know why, but I think this is a really funny thing which I never expect after I saw how simple creating a web site in django. Don't you all think so? Or if you have any other solution or anything coming-up, can you please share?

Thanks in advance...

PS. I don't mind to get along with db in shell, but what I want to know is just why it is like that in django...

A: 

They made it so that you could quickly and easily create your database with minimum effort. Unfortunately they didn't make it as easy to update the tables, you'd have to manually do an ALTER TABLE. I think they may be working on fixing this for Django 1.1, but I'm not entirely sure on that.

AlbertoPL
+1  A: 

I use South to help stop problems like these (although it seems to have problems with re-naming fields).

I think this behaviour may be due to the different DB back ends that Django Supports and according to these release notes there is no change in Django 1.1RC

Frozenskys
+4  A: 

Database migration is a goal for the django project, but it was a difficult enough topic that it didn't end up in the first several versions. A number of migration projects emerged to fill in the gap, and each one solves the difficult problem in different ways. Rather than trying to create an additional migration solution, or blessing one with 'official' status before any had matured, or at least emerged as the single preferred solution, the django team decided to just let those solutions evolve and will pick one from the crop at a later date to ship with django.

As for more info about those third party migration tools, look at the answers to this question.

TokenMacGuy
+1  A: 

Several of the above answers have good information. However, based on the question it sounds like the questioner may not have used the reset command in manage.py. During the development process, as you build your models and data, you probably do not have data that needs to persist. Seed data can be stored as initial_data (http://docs.djangoproject.com/en/dev/howto/initial-data/) and can be automatically or manually added when resetting and syncing the database.

During development keeping various sets of data that can be loaded and liberal use of the reset command in manage.py is key to working with evolving models. However, once you're in production, the migration tools (or manual DB tweaks) become essential.

shawnr