django版本和mysql不兼容导致报错django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the dj

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 <module>
    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以上重置初始密码的方法)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值