1

I somehow screwed up my migrations when creating the database for a new project. I now have the problem of migrations that don't apply:

Operations to perform:
  Apply all migrations: wagtailusers, wagtailembeds, wagtailadmin, sessions, admin, wagtailcore, auth, contenttypes, wagtaildocs, taggit, wagtailsearch, home, wagtailforms, wagtailredirects, wagtailimages
Running migrations:
  No migrations to apply.

Based on this answer (and a few others), it seems like my best bet is to clear stuff out of the django_migrations table. So I ran:

DELETE FROM django_migrations WHERE app='wagtailusers';

and got the error:

ERROR:  relation "django_migrations" does not exist

How can django_migrations not exist? What am I doing wrong? I basically want to scrub everything in the database and all the migrations and start over from scratch, but it's apparently far more complicated than I suspected. (Is there a simpler way to basically start over with the database and migrations?)

EDIT:

I tried reverting one app and migrating it forward again.

I ran ./manage.py showmigrations wagtailusers, which showed all migrations applied:

wagtailusers
 [X] 0001_initial
 [X] 0002_add_verbose_name_on_userprofile
 [X] 0003_add_verbose_names
 [X] 0004_capitalizeverbose

I then unapplied all of the migrations with ./manage.py migrate wagtailusers zero:

Operations to perform:
  Unapply all migrations: wagtailusers
Running migrations:
  Rendering model states... DONE
  Unapplying wagtailusers.0004_capitalizeverbose... OK
  Unapplying wagtailusers.0003_add_verbose_names... OK
  Unapplying wagtailusers.0002_add_verbose_name_on_userprofile... OK
  Unapplying wagtailusers.0001_initial... OK

showmigrations then shows them all unapplied. So I then reapply the migrations with ./manage.py migrate wagtailusers:

Operations to perform:
  Apply all migrations: wagtailusers
Running migrations:
  Rendering model states... DONE
  Applying wagtailusers.0001_initial... OK
  Applying wagtailusers.0002_add_verbose_name_on_userprofile... OK
  Applying wagtailusers.0003_add_verbose_names... OK
  Applying wagtailusers.0004_capitalizeverbose... OK

Everything is checked in showmigrations. But when I run migrate again, it still seems to think there's something missing?

Operations to perform:
  Apply all migrations: wagtailusers
Running migrations:
  No migrations to apply.
Community
  • 1
  • 1
Julia Ebert
  • 1,583
  • 1
  • 21
  • 39
  • Such questions are a bit difficult to answer because we don exactly know what may have gone wrong somewhere. If it is a development machine you can always drop the entire schema. – Wtower Apr 21 '16 at 18:38
  • The problem is that I also don't know what's gone wrong. – Julia Ebert Apr 21 '16 at 19:15
  • 1
    If you don't have anything in the DB that you care about, just drop the DB and re-create it. Assuming this is postgres a `dropdb databasename && createdb -O django_user -T template0 -E UTF-8 databasename` should get you back to being able to say `manage.py migrate` – Paul Apr 21 '16 at 20:31
  • I thought that fixed my problem, but it appears to have done the same thing as `./manage.py reset_db`. I reran `./manage.py migrate` and it applied the migrations that got it up to the same point as before. So I'm right back where I started with this question. – Julia Ebert Apr 22 '16 at 10:35
  • Have you done makemigrations? what is your Django version? – e4c5 Apr 22 '16 at 12:51
  • `makemigrations` says "No changes detected". Django version is 1.9.5. – Julia Ebert Apr 22 '16 at 12:57

1 Answers1

0

If I'm reading this correctly, I think it's just the output is confusing? Your steps appeared to be

  • Run manage.py migrate which worked
  • Run manage.py migrate wagtailusers zero which also worked
  • Run manage.py migrate wagtailusers which worked
  • Run manage.py migrate which says No migrations to apply

If that's the exact order of events and I've understood things correctly, then yes that's actually what you want manage.py to say. It takes the migration engine a bit to see if there are any migrations, and it has to calculate a decent amount of state so it can determine if there are migrations that should be created but aren't there. If you want to double check this then manage.py showmigrations should show all your existing migrations with an [x] in front of them, thus showing them as having been applied.

Hopefully I've understood your question correctly.

Paul
  • 1,108
  • 9
  • 14