Django migrate : doesn't create tables

前端 未结 10 1712
独厮守ぢ
独厮守ぢ 2021-01-31 18:03

After some errors, I dropped my database, deleted all my migration files (I left init.py). Now, when I run

python migrate.py makemigrations   /         


        
相关标签:
10条回答
  • 2021-01-31 18:52

    Delete folder migrations and re-run. It works for me

    0 讨论(0)
  • 2021-01-31 18:57

    From Django docs, Options.managed: "If False, no database table creation or deletion operations will be performed for this model."

    And I see you have

       options={
            'db_table': 'tblclients',
            'managed': False,
        },
    

    Try setting managed=True in the model.

    0 讨论(0)
  • 2021-01-31 19:03

    First try this;

    Check your migration files for the app, if you have the create model portion in your migrations file, remove it and redo migrations. I.e remove this; migrations.CreateModel( name='YourModelName', ....... .....)

    (venv)root@debian:~/Desktop/project$ python manage.py makemigrations appName
    (venv)root@debian:~/Desktop/project$ python manage.py migrate appName
    

    Else; navigate to your database and delete all migrations for that app, you may have to drop the related tables too.

    postgres=# \c db_yourdb
    db_yourdb=# delete from django_migrations where app='appName';
    

    then go to your code and;

    (venv)root@debian:~/Desktop/project$ python manage.py makemigrations appName
    (venv)root@debian:~/Desktop/project$ python manage.py migrate appName
    

    To do fresh migrations entirely, first do the necessary deletions for migrations and droping the tables if need be then;

    (venv)root@debian:~/Desktop/project$ find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
    (venv)root@debian:~/Desktop/project$ find . -path "*/migrations/*.pyc"  -delete
    

    finally do;

    (venv)root@debian:~/Desktop/project$ python manage.py makemigrations
    (venv)root@debian:~/Desktop/project$ python manage.py migrate
    

    Read more here on how to reset migrations

    0 讨论(0)
  • 2021-01-31 19:04

    In my case, what created the tables was this:

    python manage.py migrate --run-syncdb
    

    I am using Django 1.9.6.

    0 讨论(0)
提交回复
热议问题