Django2.1迁移数据库出错

Stella981
• 阅读 674

今天迁移数据库的时候,报错:django.db.migrations.exceptions.MigrationSchemaMissing,下面是错误的详细信息:

 1 manage.py@xiaopixiu > migrate
 2 "D:\Program Files\JetBrains\PyCharm 2017.2.2\bin\runnerw.exe" C:\Users\senyu\Anaconda3\envs\py3.6.5\python.exe "D:\Program Files\JetBrains\PyCharm 2017.2.2\helpers\pycharm\django_manage.py" migrate C:/Users/senyu/Desktop/工作文件/xiaopixiu_v2.0/xiaopixiu
 3 System check identified some issues:
 4 
 5 WARNINGS:
 6 ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
 7     HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-sql-mode
 8 Operations to perform:
 9   Apply all migrations: admin, auth, authtoken, common, contenttypes, sessions
10 Running migrations:
11 Traceback (most recent call last):
12   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
13     return self.cursor.execute(sql)
14   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
15     return self.cursor.execute(query, args)
16   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
17     self.errorhandler(self, exc, value)
18   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
19     raise errorvalue
20   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
21     res = self._query(query)
22   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
23     rowcount = self._do_query(q)
24   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
25     db.query(q)
26   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\connections.py", line 277, in query
27     _mysql.connection.query(self, query)
28 _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1")
29 
30 The above exception was the direct cause of the following exception:
31 
32 Traceback (most recent call last):
33   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\migrations\recorder.py", line 55, in ensure_schema
34     editor.create_model(self.Migration)
35   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\base\schema.py", line 312, in create_model
36     self.execute(sql, params or None)
37   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
38     cursor.execute(sql, params)
39   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 100, in execute
40     return super().execute(sql, params)
41   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 68, in execute
42     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
43   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
44     return executor(sql, params, many, context)
45   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
46     return self.cursor.execute(sql, params)
47   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\utils.py", line 89, in __exit__
48     raise dj_exc_value.with_traceback(traceback) from exc_value
49   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
50     return self.cursor.execute(sql)
51   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
52     return self.cursor.execute(query, args)
53   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
54     self.errorhandler(self, exc, value)
55   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
56     raise errorvalue
57   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
58     res = self._query(query)
59   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
60     rowcount = self._do_query(q)
61   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
62     db.query(q)
63   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\MySQLdb\connections.py", line 277, in query
64     _mysql.connection.query(self, query)
65 django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1")
66 
67 During handling of the above exception, another exception occurred:
68 
69 Traceback (most recent call last):
70   File "D:\Program Files\JetBrains\PyCharm 2017.2.2\helpers\pycharm\django_manage.py", line 43, in <module>
71     run_module(manage_file, None, '__main__', True)
72   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\runpy.py", line 205, in run_module
73     return _run_module_code(code, init_globals, run_name, mod_spec)
74   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\runpy.py", line 96, in _run_module_code
75     mod_name, mod_spec, pkg_name, script_name)
76   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\runpy.py", line 85, in _run_code
77     exec(code, run_globals)
78   File "C:/Users/senyu/Desktop/工作文件/xiaopixiu_v2.0/xiaopixiu\manage.py", line 15, in <module>
79     execute_from_command_line(sys.argv)
80   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
81     utility.execute()
82   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\__init__.py", line 375, in execute
83     self.fetch_command(subcommand).run_from_argv(self.argv)
84   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
85     self.execute(*args, **cmd_options)
86   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\base.py", line 353, in execute
87     output = self.handle(*args, **options)
88   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\base.py", line 83, in wrapped
89     res = handle_func(*args, **kwargs)
90   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
91     fake_initial=fake_initial,
92   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate
93     self.recorder.ensure_schema()
94   File "C:\Users\senyu\Anaconda3\envs\py3.6.5\lib\site-packages\django\db\migrations\recorder.py", line 57, in ensure_schema
95     raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
96 django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1"))

Python版本为3.6.5, Django版本为2.1.7,,之前在本地迁移数据库的时候是很正常的,迁移到服务器上就报错,然后查看之后,发现本地数据库是5.7.22,服务端数据库版本为5.5.56,然后猜想为数据库版本问题,Django2.1生成的数据库语句和5.5版本的数据库不兼容.因此才会出现这样的错误.

之后查看了Django的发行信息

Django2.1迁移数据库出错

Djngo2.1只支持MySQL5.6(含)以上版本,所以确定就是MySQL版本问题.

并且,官方宣布,Django2.0是最后一个支持3.4版本的Python,还好我Python版本比较新一些.建议大家以后使用新版的时候,事先阅读一下新版本的新特性.嗯,就是这样

Django2.1迁移数据库出错

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
3年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Stella981 Stella981
3年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Wesley13 Wesley13
3年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Easter79 Easter79
3年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这