zjm1126
zjm1126

Reputation: 35682

how to add a new field in django model

this is my model :

class zjm_model(models.Model):
    a = models.CharField(max_length=36)
    b = models.CharField(max_length=36)

and the table zjm_model has many data in my mysql , and now ,

i want to add a new field :

class zjm_model(models.Model):
    a = models.CharField(max_length=36)
    b = models.CharField(max_length=36)
    c = models.CharField(max_length=36)

but , when i run manage.py syncdb , it show this :

No fixtures found.

so how can i to add a new field to my database ,

thanks

Upvotes: 3

Views: 1310

Answers (3)

Hyungyong Kim
Hyungyong Kim

Reputation: 45

You have to dump your previous data.

manage.py dumpdata > dump.json

And you can load your data after syncdb. ("c" column have to permit null)

manage.py loaddata dump.json

Upvotes: -2

Spacedman
Spacedman

Reputation: 94202

south is very nice and all that, but if this is a very rare one-off thing then just fire up your favourite mysql tool and do something like: ALTER TABLE foo ADD COLUMN wotsit VARCHAR(100) - I can't remember the exact syntax...

But +1 for south.

Upvotes: 5

Sam Dolan
Sam Dolan

Reputation: 32532

Database migrations are not built-in to Django, so you'll need to use a third party library. I highly recommend south.

Upvotes: 10

Related Questions