Django2.1迁移数据库出错

今天迁移数据库的时候,报错: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 
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 
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迁移数据库出错_第1张图片

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

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

Django2.1迁移数据库出错_第2张图片

 

转载于:https://www.cnblogs.com/kuoiea/p/10566153.html

你可能感兴趣的:(python,数据库,开发工具)