Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.8 migrate is not creating tables

Tags:

python

django

yekabathula-macbookair2:roster yekabathula$ python manage.py migrate Operations to perform:   Synchronize unmigrated apps: staticfiles, messages   Apply all migrations: admin, contenttypes, api, auth, sessions Synchronizing apps without migrations:   Creating tables...     Running deferred SQL...   Installing custom SQL... Running migrations:   Rendering model states... DONE   Applying contenttypes.0001_initial... OK   Applying auth.0001_initial... OK   Applying admin.0001_initial... OK   Applying api.0001_initial... OK   Applying contenttypes.0002_remove_content_type_name... OK   Applying auth.0002_alter_permission_name_max_length... OK   Applying auth.0003_alter_user_email_max_length... OK   Applying auth.0004_alter_user_username_opts... OK   Applying auth.0005_alter_user_last_login_null... OK   Applying auth.0006_require_contenttypes_0002... OK   Applying sessions.0001_initial... OK yekabathula-macbookair2:roster yekabathula$ python manage.py syncdb /Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9   warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)  Operations to perform:   Synchronize unmigrated apps: staticfiles, messages   Apply all migrations: admin, contenttypes, api, auth, sessions Synchronizing apps without migrations:   Creating tables...     Running deferred SQL...   Installing custom SQL... Running migrations:   No migrations to apply. 

After doing python manage.py migrate, tables are not created in database from my models.py it is able to create other tables from django_session etc. Is there anything else that I need to follow here ?

like image 282
YSK Avatar asked Oct 12 '15 16:10

YSK


2 Answers

I was facing a similar problem in Django 1.10 and none of the above solutions worked for me.

What eventually worked was running this command:

python manage.py migrate --fake myappname zero 

This reset all migrations (to the zeroth state)

This followed by :

python manage.py migrate myappname 

created the tables for me.

If you do not want to roll back to the initial(zero) state but say to the migration number 0005(the last migration that worked), you can instead do this:

python manage.py migrate --fake myappname 0005 

And then proceed with the actual migrate:

python manage.py migrate myappname 

More details in the docs

like image 52
bhaskarc Avatar answered Sep 21 '22 08:09

bhaskarc


In my case the __init__.py file was missing from the APP/migrations/ folder. If you don't have one, all it needs is an empty __init__.py file.

like image 25
Ljubitel Avatar answered Sep 21 '22 08:09

Ljubitel