Django migrate : doesn't create tables

前端 未结 10 1730
独厮守ぢ
独厮守ぢ 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 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

提交回复
热议问题