# 第三方登录数据表建立
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB;'
}
报错,Error 1193.该问题在mysql 5.6下易出现,添加default问题解决
'init_command': 'SET default_storage_engine=INNODB;'
在model的外键中添加“on_delete=models.CASCADE”
外键具有一对多的关系,在python manage.py makemigrations报错,主外关系键中,级联删除,也就是当删除主表的数据时候从表中的数据也随着一起删除
models.DateTimeField(default=datetime.now, verbose_name="add_time") # datetime.now
标示该数据的唯一性
解决方法就是:
from django.urls import reverse
最近从django1.9迁移到django2.0中出现一个意外的报错:
这个报错的原因在stack overflow上有很直接的解释,但是百度上并没有直接的答案。
简单来说,原因就是:django2.0 把原来的 django.core.urlresolvers 包 更改为了 django.urls包,所以我们需要把导入的包都修改一下就可以了。
下面是stack overflow上的解释:
from django.conf.urls import url, include
报错如下:
1
2
3
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 8, in
from django.core.urlresolvers import NoReverseMatch, reverse
ModuleNotFoundError: No module named 'django.core.urlresolvers'
|
解决方法:
修改D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py 文件
把from django.core.urlresolvers import NoReverseMatch, reverse 修改为:
1
|
from django.urls import NoReverseMatch, reverse
|
报错如下:
1
2
3
4
5
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 45, in
class Bookmark(models.Model):
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 49, in Bookmark
content_type = models.ForeignKey(ContentType)
TypeError: __init__() missing 1 required positional argument: 'on_delete'
|
解决方法:
把content_type = models.ForeignKey(ContentType)修改为:
1
|
content_type = models.ForeignKey(ContentType,on_delete=models.CASCADE)
|
报错如下:
1
2
3
4
|
model = ModelChoiceField(label=_(u'Target Model'), widget=exwidgets.AdminSelectWidget)
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\views\dashboard.py", line 284, in __init__
forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs)
TypeError: __init__() takes 1 positional argument but 6 were given
|
解决方法:
把forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs) 修改成:
1
|
forms.Field.__init__(self)
|
报错如下:
1
2
3
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\plugins\filters.py", line 10, in
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
ImportError: cannot import name 'QUERY_TERMS'
|
解决方法:
把
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
修改为:
1
2
|
from django.db.models.sql.query import LOOKUP_SEP
from django.db.models.sql.constants import QUERY_TERMS
|
报错如下:
1
2
3
4
5
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\plugins\language.py", line 24, in
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
File "D:\Envs\django-xadmin\lib\site-packages\django\conf\__init__.py", line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'MIDDLEWARE_CLASSES'
|
把
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_ClASSES:
修改为:
1
|
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:
|
报错如下:
1
2
3
|
File "C:\Users\laoyan\Desktop\xadmin-django2\xadmin-django2\demo_app\..\xadmin\plugins\wizard.py", line 12, in
from django.contrib.formtools.wizard.storage import get_storage
ModuleNotFoundError: No module named 'django.contrib.formtools'
|
卸载django-formtools
pip uninstall django-formtools
重新安装新版本的django-formtools
1
|
pip install django-formtools==2.1
|
python2系列可以支持 print “xxxx” ,python系列需要使用print("xxx")