3

I have an app with an initial data fixture on Django 1.8. When I run manage.py migrate, I get the following output:

Operations to perform:
  Synchronize unmigrated apps: food, locations, messages, staticfiles, core
  Apply all migrations: auth, sessions, admin, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
/home/myuser/venv/lib/python3.4/site-packages/django/core/management/commands/loaddata.py:229: RemovedInDjango19Warning: initial_data fixtures are deprecated. Use data migrations instead.
  RemovedInDjango19Warning

Installed 87 object(s) from 1 fixture(s)
Running migrations:
  No migrations to apply.

So it seems like the fixture was installed, but not really - when I log in to my postgres user and run psql and \dt, no tables are listed (I make sure to connect to the database first with \c mydatabase)! When trying to view the app in a browser, I get: ProgrammingError at / relation "locations_openinghours" does not exist. (Which just happens to be the first table that the app tries to access).

4
  • 1
    have you tried running python manage.py makemigrations before running python manage.py migrate ? Commented Nov 9, 2015 at 21:31
  • Yes, I did this before - and when I do it again, I get No changes detected. There are no folders called migrations anywhere in my project (none were created). Commented Nov 9, 2015 at 21:53
  • Can you add more info? Like show us code snippet of your model and maybe INSTALLED_APPS section of your settings? Commented Nov 9, 2015 at 22:02
  • Yes, I've done that now. Thank you! Commented Nov 9, 2015 at 22:10

2 Answers 2

2

You can try these steps to see if it resolves your problem:

  1. delete all the migration files for your app, as well as the database records for the app migrations in the django_migrations table.
  2. Run: python manage.py makemigrations <appname>
  3. Run: python manage.py migrate <appname>

In addition to the above you can try adding to each of your model classes the meta class setting managed = True and app_label = <name of your app>

i.e.

class Food(models.Model): class Meta: app_label = "food" managed = True

The rest of your class as you had it. Of course add this Meta for all your models. Make sure the app_label is lower case like you have it in the INSTALLED_APPS setting.

Sign up to request clarification or add additional context in comments.

1 Comment

This solution did not worked for me .. it actually creates default entry database but not the secondary entry which is in another section of databases also I have a database router could this be a reason? basically I am able to connect with the existing manually created database. But new postgresql database is not getting created with about migrations commands.
1

I solved it, but it was a silly issue. First, when running python manage.py makemigrations for the first time, you should specify which app you're migrating for - so I used python manage.py makemigrations myapp. Secondly, the way I've set up my project, manage.py uses the dev settings by default, and this was writing to an SQLite database. I added the --settings=core.settings.production flag, and it worked.

3 Comments

the dev setting thing has caught me out before too :-)
where did you add settings=core.settings.production flag ? do i add a line settings=core.settings.production in manage.py
I changed DB names in settings.py , then did migrations, then restarted server and it worked. I had to create new data and then it showed up in my postgres DB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.