Django學習中遇到的問題(1)django migration No migrations to apply


C:\Users\Desktop\homeWork\Django_stu_man>python manage.py makemigrations
Migrations for 'app01':
  app01\migrations\0001_initial.py
    - Create model ClassList
    - Create model Course
    - Create model CourseRecord
    - Create model Customer
    - Create model CustomerFollowRecord
    - Create model School
    - Create model StudyRecord
    - Create model UserProfile
    - Add field follower to customerfollowrecord
    - Add field consultant to customer
    - Add field course to customer
    - Add field referral_form to customer
    - Add field teacher to courserecord
    - Add field course to classlist
    - Add field teachers to classlist
    - Alter unique_together for courserecord (1 constraint(s))
    - Alter unique_together for classlist (1 constraint(s))

C:\Users\Desktop\homeWork\Django_stu_man>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, app01, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

如上所示,建完表之后,運行python manage.py migrate,總是No migrations to apply,數據庫中表也沒有建成。

通過查閱資料,大部分建議都是先運行python manage.py makemigrations,再運行python manage.py migrate,然並卵。

最后在stackoverflow上發現了正解。

 

Django keeps track of all the applied migrations in django_migrations table. So just delete all the rows in the django_migrations table that are related to you app like:

DELETE FROM django_migrations WHERE app='your-app-name';

and then do:

python manage.py makemigrations python manage.py migrate

 

C:\Users\Desktop\homeWork\Django_stu_man>python manage.py makemigrations
No changes detected

C:\Users\Desktop\homeWork\Django_stu_man>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, app01, auth, contenttypes, sessions
Running migrations:
  Applying app01.0001_initial... OK

 

binggo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

https://stackoverflow.com/questions/33549772/django-migration-no-migrations-to-apply


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM