关于Django报错 raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc

本文解决了一个在使用Django2.1进行数据库迁移时遇到的问题,原因是MySQL版本为5.5,不被支持。提供了两种解决方案:降级Django版本至2.0或升级MySQL至5.6及以上版本。

代码什么的都没有错误,但是在执行迁移命令的时候报错:

python manage.py makemigrations
python manage.py migrate

报错:

raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc

原因:

django2.1不在支持MySQL5.5 ,必须是5.6以上(我的django是2.1的,MySQL是5.1或5.5)

解决办法:

  1. 使用低版本的django,降到django2.0
    pip install Django==2.0.0 -i https://pypi.douban.com/simple
  2. 升级MySQL到5.6版本级以上,我直接吧原来的卸载了并清除干净,安装了5.7版本的(可以使用不卸载的方式升级,这里我没试过,不做说明)
Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Traceback (most recent call last): File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 82, in _execute return self.cursor.execute(sql) File "D:\Python37\lib\site-packages\django\db\backends\oracle\base.py", line 523, in execute return self.cursor.execute(query, self._param_generator(params)) cx_Oracle.DatabaseError: ORA-02000: missing ALWAYS keyword The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 68, in ensure_schema editor.create_model(self.Migration) File "D:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 345, in create_model self.execute(sql, params or None) File "D:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute cursor.execute(sql, params) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 98, in execute return super().execute(sql, params) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "D:\Python37\lib\site-packages\django\db\utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 82, in _execute return self.cursor.execute(sql) File "D:\Python37\lib\site-packages\django\db\backends\oracle\base.py", line 523, in execute return self.cursor.execute(query, self._param_generator(params)) django.db.utils.DatabaseError: ORA-02000: missing ALWAYS keyword During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "D:\Python37\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line utility.execute() File "D:\Python37\lib\site-packages\django\core\management\__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 398, in execute output = self.handle(*args, **options) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 89, in wrapped res = handle_func(*args, **kwargs) File "D:\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 246, in handle fake_initial=fake_initial, File "D:\Python37\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate self.recorder.ensure_schema() File "D:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 70, 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 (ORA-02000: missing ALWAYS keyword) 什么问题
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值