最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于django2.2連oracle11g解決版本沖突的問題

 更新時(shí)間:2020年07月02日 14:43:12   作者:觀想  
這篇文章主要介紹了基于django2.2連oracle11g解決版本沖突的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

上次用django2.2和oracle11g,在migrate的時(shí)候發(fā)生了版本沖突,最終將Oracle升級(jí)到了12c才解決問題

那么到底能不能用別的方法來解決這個(gè)沖突呢?想了個(gè)解決思路,實(shí)踐一下:

用django2.2連Oracle12c環(huán)境下做migrate,創(chuàng)建基礎(chǔ)表

將基礎(chǔ)表導(dǎo)出,再導(dǎo)入到Oracle11g數(shù)據(jù)庫中

用django2.2連Oracle11g

實(shí)施步驟

1、用django2.2連Oracle12c環(huán)境下做migrate,創(chuàng)建基礎(chǔ)表

在前文中已經(jīng)完成,連接到數(shù)據(jù)庫,可以看到有10張基礎(chǔ)表

看一張表,比如AUTH_GROUP表,發(fā)現(xiàn)有個(gè)ID字段是用了12c特有的generated語法,除了DJANGO_SESSION外,其他每張表都有一個(gè)自增序列的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. 將基礎(chǔ)表導(dǎo)出,再導(dǎo)入到Oracle11g數(shù)據(jù)庫中

導(dǎo)出django用戶數(shù)據(jù)庫,注意使用11g版本

接著導(dǎo)入到11g數(shù)據(jù)庫中,非常順利

再看AUTH_GROUP表,發(fā)現(xiàn)表結(jié)構(gòu)是一樣的,但是id上面自增序列的默認(rèn)值沒有了。

-- 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,然后啟動(dòng)django服務(wù),果然成功啟動(dòng)

但是,但是,創(chuàng)建admin用戶密碼的時(shí)候就報(bào)錯(cuò)了,ORA-01400: cannot insert NULL into (“DJANGO”.“AUTH_USER”.“ID”)

PS D:\parttime\python\django\guanxiangzhiji> python manage.py createsuperuser
用戶名 (leave blank to use 'administrator'):
電子郵件地址:
Password:
Password (again):
密碼長度太短。密碼必須包含至少 8 個(gè)字符。
這個(gè)密碼太常見了。
Bypass password validation and create user anyway? [y/N]: y
Traceback (most recent call last):
 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\backends\oracle\base.py", line 510, in execute
 return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.IntegrityError: ORA-01400: cannot insert NULL into ("DJANGO"."AUTH_USER"."ID")

The above exception was the direct cause of the following exception:

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\contrib\auth\management\commands\createsuperuser.py", line 61, in execute
 return super().execute(*args, **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\contrib\auth\management\commands\createsuperuser.py", line 156, in handle
 self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
 File "D:\app\anaconda\lib\site-packages\django\contrib\auth\models.py", line 162, in create_superuser
 return self._create_user(username, email, password, **extra_fields)
 File "D:\app\anaconda\lib\site-packages\django\contrib\auth\models.py", line 145, in _create_user
 user.save(using=self._db)
 File "D:\app\anaconda\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
 super().save(*args, **kwargs)
 File "D:\app\anaconda\lib\site-packages\django\db\models\base.py", line 741, in save
 force_update=force_update, update_fields=update_fields)
 File "D:\app\anaconda\lib\site-packages\django\db\models\base.py", line 779, in save_base
 force_update, using, update_fields,
 File "D:\app\anaconda\lib\site-packages\django\db\models\base.py", line 870, in _save_table
 result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
 File "D:\app\anaconda\lib\site-packages\django\db\models\base.py", line 908, in _do_insert
 using=using, raw=raw)
 File "D:\app\anaconda\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
 return getattr(self.get_queryset(), name)(*args, **kwargs)
 File "D:\app\anaconda\lib\site-packages\django\db\models\query.py", line 1186, in _insert
 return query.get_compiler(using=using).execute_sql(return_id)
 File "D:\app\anaconda\lib\site-packages\django\db\models\sql\compiler.py", line 1335, in execute_sql
 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 84, in _execute
 return self.cursor.execute(sql, params)
 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.IntegrityError: ORA-01400: cannot insert NULL into ("DJANGO"."AUTH_USER"."ID")

原因分析

很明顯,插入到AUTH_USER表時(shí),沒有指定ID的值,而ID是主鍵,非空。

因?yàn)樵?2c的環(huán)境下,這個(gè)ID是自增序列,insert語句中不需要指定這個(gè)值。

解決方案

解決方案也應(yīng)運(yùn)而出了,只要為每個(gè)ID列創(chuàng)建一個(gè)11g的序列,創(chuàng)建觸發(fā)器,在插入數(shù)據(jù)時(shí)補(bǔ)上id值就行了。

(1)生成序列。

用sql語句

select 'create sequence seq_'||table_name||' minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;'
 from user_tab_columns
 where column_name='ID';

生成創(chuàng)建序列的批量執(zhí)行語句,并執(zhí)行。

create sequence seq_DJANGO_ADMIN_LOG minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_USER minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_USER_GROUPS minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_DJANGO_CONTENT_TYPE minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_GROUP minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_GROUP_PERMISSIONS minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_DJANGO_MIGRATIONS minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_PERMISSION minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;
create sequence seq_AUTH_USER_USER_PERMISSIONS minvalue 1 maxvalue 999999999 start with 1 increment by 1 cache 20;

(2)創(chuàng)建觸發(fā)器

用SQL語句

select 'create or replace trigger tri_'||table_name||'
 before insert
 on '||table_name||' 
 for each row
 declare
 begin
 :new.id:=seq_'||table_name||'.nextval;
 end tri_'||table_name||';
 /'
 from user_tab_columns
 where column_name='ID';

生成觸發(fā)器腳本:

create or replace trigger tri_DJANGO_MIGRATIONS
	before insert
	on DJANGO_MIGRATIONS
	for each row
declare
begin
	:new.id:=seq_DJANGO_MIGRATIONS.nextval;
end tri_DJANGO_MIGRATIONS;
/
create or replace trigger tri_DJANGO_CONTENT_TYPE
	before insert
	on DJANGO_CONTENT_TYPE
	for each row
declare
begin
	:new.id:=seq_DJANGO_CONTENT_TYPE.nextval;
end tri_DJANGO_CONTENT_TYPE;
/
create or replace trigger tri_AUTH_PERMISSION
	before insert
	on AUTH_PERMISSION
	for each row
declare
begin
	:new.id:=seq_AUTH_PERMISSION.nextval;
end tri_AUTH_PERMISSION;
/
create or replace trigger tri_AUTH_GROUP
	before insert
	on AUTH_GROUP
	for each row
declare
begin
	:new.id:=seq_AUTH_GROUP.nextval;
end tri_AUTH_GROUP;
/
create or replace trigger tri_AUTH_GROUP_PERMISSIONS
	before insert
	on AUTH_GROUP_PERMISSIONS
	for each row
declare
begin
	:new.id:=seq_AUTH_GROUP_PERMISSIONS.nextval;
end tri_AUTH_GROUP_PERMISSIONS;
/
create or replace trigger tri_AUTH_USER
	before insert
	on AUTH_USER
	for each row
declare
begin
	:new.id:=seq_AUTH_USER.nextval;
end tri_AUTH_USER;
/
create or replace trigger tri_AUTH_USER_GROUPS
	before insert
	on AUTH_USER_GROUPS
	for each row
declare
begin
	:new.id:=seq_AUTH_USER_GROUPS.nextval;
end tri_AUTH_USER_GROUPS;
/
create or replace trigger tri_AUTH_USER_USER_PERMISSIONS
	before insert
	on AUTH_USER_USER_PERMISSIONS
	for each row
declare
begin
	:new.id:=seq_AUTH_USER_USER_PERMISSIONS.nextval;
end tri_AUTH_USER_USER_PERMISSIONS;
/
create or replace trigger tri_DJANGO_ADMIN_LOG
	before insert
	on DJANGO_ADMIN_LOG
	for each row
declare
begin
	:new.id:=seq_DJANGO_ADMIN_LOG.nextval;
end tri_DJANGO_ADMIN_LOG;
/

(3)此時(shí)再創(chuàng)建admin用戶,就成功了

新增用戶lurenjia成功!

以上這篇基于django2.2連oracle11g解決版本沖突的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python操作xlwings的實(shí)例詳解

    Python操作xlwings的實(shí)例詳解

    python操作Excel的模塊,網(wǎng)上提到的模塊大致有:xlwings、xlrd、xlwt、openpyxl、pyxll等。本文將通過幾個(gè)實(shí)例演示下xlwings的使用,感興趣的可以了解一下
    2022-07-07
  • python如何將繪制的圖片保存為矢量圖格式(svg)

    python如何將繪制的圖片保存為矢量圖格式(svg)

    這篇文章主要介紹了python如何將繪制的圖片保存為矢量圖格式(svg)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Python?socket如何解析HTTP請求內(nèi)容

    Python?socket如何解析HTTP請求內(nèi)容

    這篇文章主要介紹了Python?socket如何解析HTTP請求內(nèi)容,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • Django中間件攔截未登錄url實(shí)例詳解

    Django中間件攔截未登錄url實(shí)例詳解

    在本篇文章里小編給各位整理了關(guān)于Django中間件攔截未登錄url的實(shí)例內(nèi)容以及相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。
    2019-09-09
  • pyEcharts安裝及詳細(xì)使用指南(最新)

    pyEcharts安裝及詳細(xì)使用指南(最新)

    這篇文章主要介紹了pyEcharts安裝及詳細(xì)使用指南(最新),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 如何利用Python模擬GitHub登錄詳解

    如何利用Python模擬GitHub登錄詳解

    這篇文章主要給大家介紹了關(guān)于如何利用Python模擬GitHub登錄的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 詳解如何使用python腳本制作生成CANdbc

    詳解如何使用python腳本制作生成CANdbc

    這篇文章主要為大家詳細(xì)介紹了如何使用python腳本制作生成CANdbc,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解下
    2024-01-01
  • pycharm配置anaconda環(huán)境時(shí)找不到python.exe的兩種解決辦法

    pycharm配置anaconda環(huán)境時(shí)找不到python.exe的兩種解決辦法

    如果你在Anaconda中創(chuàng)建了虛擬環(huán)境,但是無法找到python.exe,可能是因?yàn)樘摂M環(huán)境的Python路徑?jīng)]有添加到系統(tǒng)環(huán)境變量中,這篇文章主要給大家介紹了關(guān)于pycharm配置anaconda環(huán)境時(shí)找不到python.exe的兩種解決辦法,需要的朋友可以參考下
    2024-07-07
  • 詳解Python中的文件操作

    詳解Python中的文件操作

    在日常生活中,文件操作主要包括打開、關(guān)閉、讀、寫等操作,這篇文章主要為大家詳細(xì)介紹了Python中這些文件操作的實(shí)現(xiàn),需要的可以了解下
    2023-07-07
  • OpenCV學(xué)習(xí)之圖像形態(tài)學(xué)處理詳解

    OpenCV學(xué)習(xí)之圖像形態(tài)學(xué)處理詳解

    這篇文章主要為大家詳細(xì)介紹了OpenCV中圖像形態(tài)學(xué)處理的相關(guān)知識(shí),例如:腐蝕操作、膨脹操作、開閉運(yùn)算、梯度運(yùn)算、Top Hat Black Hat運(yùn)算等操作,需要的可以參考一下
    2023-02-02

最新評(píng)論

梧州市| 大同市| 绥芬河市| 望城县| 肃北| 晋宁县| 余姚市| 商南县| 禄丰县| 中宁县| 龙岩市| 红桥区| 壤塘县| 台北市| 九寨沟县| 通许县| 东乡族自治县| 平顺县| 山东省| 娄底市| 临洮县| 安乡县| 曲沃县| 崇左市| 商城县| 建水县| 嘉峪关市| 壤塘县| 南阳市| 石泉县| 枝江市| 普陀区| 平山县| 象州县| 河南省| 安阳县| 崇信县| 涪陵区| 太仓市| 乌拉特前旗| 大城县|