F:\Python\workspace\HelloWorld>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql)
File "C:\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 74, in execute
return self.cursor.execute(query, args)
File "C:\Python37\lib\site-packages\MySQLdb\cursors.py", line 209, in execute
res = self._query(query)
File "C:\Python37\lib\site-packages\MySQLdb\cursors.py", line 315, in _query
db.query(q)
File "C:\Python37\lib\site-packages\MySQLdb\connections.py", line 239, in query
_mysql.connection.query(self, query)
MySQLdb._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")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 67, in ensure_schema
editor.create_model(self.Migration)
File "C:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 324, in create_model
self.execute(sql, params or None)
File "C:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
cursor.execute(sql, params)
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Python37\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql)
File "C:\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 74, in execute
return self.cursor.execute(query, args)
File "C:\Python37\lib\site-packages\MySQLdb\cursors.py", line 209, in execute
res = self._query(query)
File "C:\Python37\lib\site-packages\MySQLdb\cursors.py", line 315, in _query
db.query(q)
File "C:\Python37\lib\site-packages\MySQLdb\connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQ
L server version for the right syntax to use near '(6) NOT NULL)' at line 1")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 233, in handle
fake_initial=fake_initial,
File "C:\Python37\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate
self.recorder.ensure_schema()
File "C:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 69, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an erro
r 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"))
在使用django3.0.3和MySQL5.5版本过程中报错,搜索相关问题后,总结如下:、
由于django已经接近最新, MySQL版本较早。加上MySQL性能8.0.x是5.5.x版本的2倍,就换成更高版本的8.0.x
这里直接 下载 8.0.20版本 MySQL
1.从新将MySQL解压后的bin目录加入到环境变量中
2.进入bin目录,按住shift键然后点击鼠标右键可以选择在该目录下打开命令窗口,或者在地址栏中输入cmd进入命令窗口。输入mysql -u root -p后回车,然后会提示输入密码,输入密码后就会进入MySQL的操作管理界面。 (这里可能不知道默认的密码,需要重置,是个大坑, 遇到的客官请自行搜索: Mysql8.0以上重置初始密码的方法)