在写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:
- Provide a one-off default now (will be set on all existing rows with a null value for this column)
- 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
- Add field user_wx_openid to user
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 http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
如此问题解决了。
版权声明
本文章由作者“衡于墨”创作,转载请注明出处,未经允许禁止用于商业用途
评论区#
还没有评论哦,期待您的评论!
引用发言