3

I renamed some django app , and now want to run migrate to update the database. But I get the following error because the old names still are still referenced in the migrations files.

ValueError: Lookup failed for model referenced by field pr1.Ticket.project: prod.Project

I already tried ./manage.py flush to reset the database, but that doesn't seem to help.
What is the correct way to 'reset' or initialize the migrations?

Alex
  • 5,759
  • 1
  • 32
  • 47
  • Have you tried http://stackoverflow.com/questions/8408046/how-to-change-the-name-of-a-django-app ? – Sylvain Biehler May 19 '15 at 11:27
  • @Bilou06 something similar. However, not the sql command, because I simply `flush`ed the database. Renaming everything went fine. only place where the old name still exists is in the migrations files. – Alex May 19 '15 at 11:32
  • The part "5. (For Django >= 1.7) Update the django_migrations table to avoid having your previous migrations re-run: UPDATE django_migrations SET app='' WHERE app=''" doesn't do it ? – Sylvain Biehler May 19 '15 at 11:35
  • If you were ready to flush the db, you might as well delete the db file and run makemigrations – Sylvain Biehler May 19 '15 at 11:37
  • migrate or makemigrations is what gives the error. (I'm using mysql, not sqlite.) – Alex May 19 '15 at 11:42
  • After you drop your database you need to remove and recreate your migrations for this app too. Try with this app only but you may run into errors when another app depends on renamed one in its migrations. – jacekbj May 19 '15 at 12:11

1 Answers1

3

If you don't care about your migrations, and the data, just delete the content of the migrations folder and create them again:

rm -f yourapp/migrations/*
touch yourapp/migrations/__init__.py
./manage.py makemigrations
Renan Ivo
  • 1,368
  • 9
  • 17