OperationalError: no such column: jianzhi_app_user.user_wx_openid
在寫django後端時報錯:
OperationalError: no such column: jianzhi_app_user.user_wx_openid
檢查了一下程式碼,views.py並沒有使用到這個user_wx_openid。
是什麼問題呢?
是因為models.py修改了,新添了user_wx_openid這一條屬性,但是忘記了執行更新。
在命令列執行如下操作:
標紅為該輸入的地方。
C:\Python27\MyDjango\jianzhi_002>python manage.py makemigrations
You are trying to add a non-nullable field ‘user_wx_openid’ to user without a default; we can’t do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now
Type ‘exit’ to exit this prompt
>>>‘’
Migrations for ‘jianzhi_app’:
jianzhi_app\migrations\0030_user_user_wx_openid.py
- Add field user_wx_openid to user
C:\Python27\MyDjango\jianzhi_002>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, jianzhi_app, sessions
Running migrations:
Applying jianzhi_app.0030_user_user_wx_openid… OK
C:\Python27\MyDjango\jianzhi_002>python manage.py runserver
Performing system checks…
System check identified no issues (0 silenced).
September 03, 2018 - 12:16:56
Django version 1.11.14, using settings ‘jianzhi_002.settings’
Starting development server at
Quit the server with CTRL-BREAK.
如此問題解決了。