Wednesday, September 30, 2015

Re: Corrupted Migration?

Thanks for the reply. I should have mentioned that I tried all of that: the problem is the model state is ahead of the database state, not behind it. It seems that the database migration was atomic, so everything was rolled back as that transaction failed, but the same thing didn't happen at the model level. So, now I'm stuck with a model state that the previous migrations don't capture.

On Wednesday, September 30, 2015 at 5:08:22 AM UTC-7, Mike Dewhirst wrote:
On 30/09/2015 4:16 PM, Daniel Chen wrote:
> Hi all,
>
> A migration I was running (manage.py migrate) died in the middle. I
> deleted the migration file, fixed the problem (wrong default value),
> recreated the migration, and re-ran it. But now, I'm getting an
> inconsistent state (error message: [Model] has no field named [field]).
> When I check the database, all the old fields are there. However, when I
> hop into a Django shell (manage.py shell) and check the model fields
> ([Model]._meta.fields), they reflect the new, post-migration state. What
> is going on, and how do I fix this?

Do it again. Delete the migration. Take note of the last valid
migration. Open the django_migrations table and delete the migration
record(s) after the last valid migration.

makemigrations again and then migrate again to bring the database into
line with your models.

BTW, the shell is looking at the model not the database.

Mike

>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/95f33338-c53b-497d-8dcd-a4c1e444b5c4%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/95f33338-c53b-497d-8dcd-a4c1e444b5c4%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/559fd3eb-36e4-4ace-a270-3caf1e7fd874%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment