How to add a new field to 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_modelcontains a lot of 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 will show the following:

No fixtures found.

since I can add a new field to my database,

thank

+3
source share
3 answers

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

+10
source

, , mysql - : ALTER TABLE foo ADD COLUMN wotsit VARCHAR (100) - ...

+1 .

+5

You must reset your previous data.

manage.py dumpdata > dump.json

And you can upload your data after syncdb. (column "c" must be null)

manage.py loaddata dump.json
-2
source

Source: https://habr.com/ru/post/1791945/


All Articles