【问题标题】:django.db.utils.DatabaseError: ORA-30673: column to be modified is not an identity columndjango.db.utils.DatabaseError: ORA-30673: column to be modified is not an identity column
【发布时间】:2018-10-09 07:03:44
【问题描述】:

谢谢大家, 我有一个 django 项目,这是我的环境:

数据库: Oracle Database 12c 企业版 12.1.0.2.0 - 64 位生产

Python: Python 3.5.1rc1 cx-Oracle==6.3 Django==2.0.4

我正在尝试这个:

 python manage.py test

我收到此错误:

django.db.utils.DatabaseError: ORA-30673: column to be modified is not an identity column

谢谢。

【问题讨论】:

标签: python django oracle


【解决方案1】:

您似乎正在尝试使用 ALTER TABLE 命令将一列设置为标识列。但是,Oracle 告诉您不能这样做。

一个例子:

创建表:

create table test (id number);

此命令引发 ORA-30673:

alter table test modify id number generated by default on null as identity;

您应该创建一个新的标识列:

alter table test add id_new number generated by default on null as identity;

如果需要,然后将数据复制到一个新列中:

update test set id_new = id;

删除旧的 ID 列:

alter table test drop column id;

将新列重命名为旧名称:

alter table test rename column id_new to id;

如果旧的 ID 列是主键,用于强制外键约束,预计会出现问题。

【讨论】:

  • 嗨!!,谢谢你的回答,我做了你给我看的例子,我从数据库的角度理解异常,但我不知道问题是否来自 django。我创建了一个新项目,但我无法执行迁移步骤。问候
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-25
  • 2015-07-21
  • 2020-07-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-26
相关资源
最近更新 更多