On 1/10/2015 6:51 AM, Daniel Chen wrote:
> 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.
The model is the master. It is outside the transaction and will never be
touched by migrations.
Your task is to identify which previous migration matches the current
database structure and delete all migrations after that point. That
means deleting the migration files after the one you identified AND
deleting the migration records in django_migrations in the database.
Thereafter, the next migration will pick up all the changes in the model
and bring the database back into alignment.
This is all much the same as I said last time so if this doesn't work it
means I haven't understood your problem.
>
> 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 <javascript:>
> > <mailto:django-users+unsubscribe@googlegroups.com <javascript:>>.
> > To post to this group, send email to django...@googlegroups.com
> <javascript:>
> > <mailto:django...@googlegroups.com <javascript:>>.
> > Visit this group at http://groups.google.com/group/django-users
> <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>
>
> >
> <https://groups.google.com/d/msgid/django-users/95f33338-c53b-497d-8dcd-a4c1e444b5c4%40googlegroups.com?utm_medium=email&utm_source=footer
> <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
> <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
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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
> <https://groups.google.com/d/msgid/django-users/559fd3eb-36e4-4ace-a270-3caf1e7fd874%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/560C6B9A.9050009%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment