上次用django2.2和oracle11g,在migrate的时候发生了版本冲突,最终将Oracle升级到了12c才解决问题
那么到底能不能用别的方法来解决这个冲突呢?想了个解决思路,实践一下:
- 用django2.2连Oracle12c环境下做migrate,创建基础表
- 将基础表导出,再导入到Oracle11g数据库中
- 用django2.2连Oracle11g
实施步骤
1、用django2.2连Oracle12c环境下做migrate,创建基础表
在前文中已经完成,连接到数据库,可以看到有10张基础表
看一张表,比如AUTH_GROUP表,发现有个ID字段是用了12c特有的generated语法,除了DJANGO_SESSION外,其他每张表都有一个自增序列的id字段作为主键。
-- Create table
create table AUTH_GROUP
(
id NUMBER(11) generated by default on null as identity,
name NVARCHAR2(150)
)
tablespace DJANGO;
-- Create/Recreate primary, unique and foreign key constraints
alter table AUTH_GROUP
add primary key (ID)
using index
tablespace DJANGO;
alter table AUTH_GROUP
add unique (NAME)
using index
tablespace DJANGO;
2. 将基础表导出,再导入到Oracle11g数据库中
导出django用户数据库,注意使用11g版本
接着导入到11g数据库中,非常顺利
再看AUTH_GROUP表,发现表结构是一样的,但是id上面自增序列的默认值没有了。
-- Create table
create table AUTH_GROUP
(
id NUMBER(11) not null,
name NVARCHAR2(150)
)
tablespace DJANGO;
-- Create/Recreate primary, unique and foreign key constraints
alter table AUTH_GROUP
add primary key (ID)
using index
tablespace DJANGO;
alter table AUTH_GROUP
add unique (NAME)
using index
tablespace DJANGO;
3、用django2.2连Oracle11g
修改settings文件,连Oracle11g,然后启动django服务,果然成功启动