解决django migrate报错ORA-02000: missing ALWAYS keyword
作者:观想 时间:2023-04-15 14:19:54
错误信息
PS D:\parttime\python\django\guanxiangzhiji> python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Traceback (most recent call last):
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "D:\app\anaconda\lib\site-packages\django\db\backends\oracle\base.py", line 510, 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:\app\anaconda\lib\site-packages\django\db\migrations\recorder.py", line 67, in ensure_schema
editor.create_model(self.Migration)
File "D:\app\anaconda\lib\site-packages\django\db\backends\base\schema.py", line 307, in create_model
self.execute(sql, params or None)
File "D:\app\anaconda\lib\site-packages\django\db\backends\base\schema.py", line 137, in execute
cursor.execute(sql, params)
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "D:\app\anaconda\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\app\anaconda\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "D:\app\anaconda\lib\site-packages\django\db\backends\oracle\base.py", line 510, 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 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "D:\app\anaconda\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\app\anaconda\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\app\anaconda\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\app\anaconda\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "D:\app\anaconda\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "D:\app\anaconda\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle
fake_initial=fake_initial,
File "D:\app\anaconda\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate
self.recorder.ensure_schema()
File "D:\app\anaconda\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 (ORA-02000: missing ALWAYS keyword)
环境情况
1、操作系统:Win10 64bit
2、Python版本:3.7.3
3、django版本:2.2.4
4、Oracle版本:11.2.0.4
5、cx_oracle版本:7.0.0
6、settings配置
原因分析
从错误提示ORA-02000: missing ALWAYS keyword看,是SQL语法错误,创建表的时候使用了Always这个关键词。 Always是在Oracle12c的新特性自增序列里用到的,语法如下:
generated-column-spec
[ GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY
[ ( START WITH IntegerConstant
[ ,INCREMENT BY IntegerConstant] ) ] ] ]
但是,我机器上用的是Oracle11.2.0.4版本,这个语法在11g版本里执行自然就会报ORA-02000的错误。
解决方案
看了网上的一些解决方案,主要有2种:
(1)将Oracle升级到12c
(2)将cx_oracle降低版本
刚开始选用方案(2),觉得简单,但是实际操作下来,问题一环套一环,比如说将cx_oracle降低版本后,接着出现了django版本与cx_oracle版本不适应的情况,接着又降低django版本。。。接着做还是不行,最终放弃了。不知道有没有人成功过。
重新选择方案(1),装了Oracle12.1.0.2
再将django和cx_oracle升级回最新版本,migrate的时候就成功了
来源:https://blog.csdn.net/yoursly/article/details/99695767
标签:django,migrate,ORA-02000
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python编程之requests在网络请求中添加cookies参数方法详解
2023-07-03 00:48:23
Python 统计列表中重复元素的个数并返回其索引值的实现方法
2023-07-15 12:31:24
![](https://img.aspxhome.com/file/2023/9/77679_0s.png)
python2.7和NLTK安装详细教程
2021-03-30 22:41:19
MySQL图形化管理工具Navicat安装步骤
2024-01-29 05:00:45
![](https://img.aspxhome.com/file/2023/9/121239_0s.png)
Python编程实现简单的微博自动点赞
2021-05-14 06:43:12
![](https://img.aspxhome.com/file/2023/4/128204_0s.jpg)
Django 后台带有字典的列表数据与页面js交互实例
2021-12-01 01:59:39
asp中日期时间函数介绍
2013-06-01 20:01:03
python多进程中的内存复制(实例讲解)
2022-01-20 23:34:46
![](https://img.aspxhome.com/file/2023/0/107030_0s.jpg)
.NET5控制台程序使用EF连接MYSQL数据库的方法
2024-01-25 08:07:43
golang网络通信超时设置方式
2024-05-09 09:39:27
![](https://img.aspxhome.com/file/2023/2/127372_0s.jpg)
详解Go语言RESTful JSON API创建
2024-04-26 17:34:17
在ORACLE移动数据库文件
2024-01-17 02:44:36
分享一个超好用的php header下载函数
2023-09-03 21:31:43
python解压TAR文件至指定文件夹的实例
2023-09-29 04:00:18
儿童python练习实例
2023-12-13 04:26:32
用python实现的可以拷贝或剪切一个文件列表中的所有文件
2022-09-11 11:28:23
SQL Serve数据库到DB2连接服务器的实现过程全解
2010-08-31 15:06:00
Python简单生成随机数的方法示例
2021-01-21 02:30:37
Python带动态参数功能的sqlite工具类
2022-10-02 14:05:15
vue开发心得和技巧分享
2024-04-30 10:30:27