Domanda

My model was

class Author(Page):
    dob = models.DateField("Date of birth")

i removed dob field and updated model with:

class Author(Page):
    name = models.CharField(max_length = 250)
    email = models.EmailField()

Then entered two commands:

python manage.py schemamigration project_name 001_initial--add-field Author.name, Author.email 

then this command

python manage.py migrate project_name

you can see attach image : these above commands don't allow me to save changes in models.

enter image description here

Need your assistance!

È stato utile?

Soluzione

SOLUTION:

1)Before adding your new field go to command prompt and move to directory where your project or application is . Now write this command before adding fields in models.py file python manage.py schemamigration your_project_or_app_name --initial

2)Now write this command python manage.py migrate your_project_or_app_name --fake 0001 (or whichever migration number it returned - 0001 is you migration number) to set the south database to that state (tables already created).

3)Now go to your models.py file an add your new fields in your models.py file, then in your cmd run this command python manage schemamigration your_project_or_app_name --auto

4)Last step to save changes run this last migrate command python manage.py migrate your_project_or_app_name

Solution Reference :Django & South: Adding new field but DatabaseError occurs "table already exists" by Yuji 'Tomita' Tomita

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top