django inspectdb oracle(资料备份)

注意,本文是作者自己备份用,django oracle相关技术资料,请参考 oracle-django总结

 

https://stackoverflow.com/questions/4914775/django-inspectdb-issue-using-oracle-database

 https://blog.csdn.net/sky6even/article/details/102506068

 

 因为 python2.0支持oracl11g, 一部分人的做法如下

这个搭配可以:

 

I have a similar setup at the top of my settings.py to set my environment variables for my oracle driver (Oracle 11.2). Not sure if this will help in your specific case.

### SETTING  UP THE ENVIRONENT FOR OUR ORACLE RPM 
import os
os.putenv('ORACLE_HOME', '/.../oracle/11.2') 
os.putenv('LD_LIBRARY_PATH', '/.../oracle/11.2/lib')

I have had no issues with manage.py inspectdb (Django 1.2.7 and Django 1.4) on Oracle 11.2.

 

 

第二部分:继承现有的数据库,融入到django开发环境

1、setting.py配置现有数据库

 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

 

可以调动起数据库工具,一般不用

 

python manage.py dbshell

导出model.py ,也可以制定某个app,也可以全部导出

python manage.py inspectdb > models.py

导出的model.py是不可以make migrations 和migrate的,除非去掉下面注释(绿色)

class Example(models.Model):
  ...
    
  class Meta:
    managed = False # remove this line
    db_table = 'example_table_name'

 

必须假装追加了initial migratios  for the existing tables

python manage.py makemigrations     #这个指令不会有任何错误
python manage.py migrate --fake-initial  #必须fake模式,假装创建了表,因为表已经存在了。

 

现在可以正常使用 existing tables model了

 

posted @ 2020-06-02 20:04  花生与酒  阅读(293)  评论(0编辑  收藏  举报