Python: You have unapplied migrations

Python 1 มิ.ย. 2016

ตอนที่ run server
จะมีข้อความนี้ขึ้นมาเตือน

You have unapplied migrations; your app may not work properly until they are applied.
Run ‘python manage.py migrate’ to apply them.

หากต้องการเช็คว่า มีส่วนไหนบ้างที่ยังไม่ได้ migrations ให้ใช้คำสั่งนี้เพื่อตรวจสอบดู

$ python manage.py showmigrations --list

admin
 [ ] 0001_initial
 [ ] 0002_logentry_remove_auto_add
auth
 [ ] 0001_initial
 [ ] 0002_alter_permission_name_max_length
 [ ] 0003_alter_user_email_max_length
 [ ] 0004_alter_user_username_opts
 [ ] 0005_alter_user_last_login_null
 [ ] 0006_require_contenttypes_0002
 [ ] 0007_alter_validators_add_error_messages
contenttypes
 [ ] 0001_initial
 [ ] 0002_remove_content_type_name
sessions
 [ ] 0001_initial

ให้ใช้คำสั่ง python manage.py migrate เพื่อ migrate ทั้งหมด

ทดสอบ show migrations อีกครั้งจะเห็นว่า

$ python manage.py showmigrations --list

admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
sessions
 [X] 0001_initial

เมื่อ run server จะเป็นปกติแล้ว

python manage.py runserver

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.