配置postgresql和sqlitedb3时出错

时间:2017-03-26 07:26:25

标签: django postgresql sqlite

我正在研究一个django项目,我正在配置sqlite3中的预配置数据库以在本地发布。首先,我已经完成了对sqlite3数据库的所有迁移,所有工作正常。 之后我想迁移到postgressql所以我创建了一个本地数据库并连接到它... iam迁移的模型是::

lblstatus

这是Django生成的两个DDL数据库:: sqlite3工作正常-----

Invalid

postgress ddl在Django ::

生成后发生了变化
class State(models.Model):
    statename = models.CharField(db_column='statename',max_length=26,unique=True)

    def __str__(self):
        return self.statename


class College(models.Model):

    statename= models.ForeignKey(State,db_column='statename',on_delete=models.CASCADE,to_field='statename')#used to_field to convert int to text must set unique to true for operation
    collegename = models.CharField(db_column='collegename',max_length=30,unique=True)

    def __str__(self):
        return self.collegename

错误,即我犯了他的后移动::

CREATE TABLE api_state
(
    id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    statename varchar(25) NOT NULL
);
CREATE UNIQUE INDEX sqlite_autoindex_api_state_1 ON api_state 
(statename);
CREATE TABLE api_college
(
    id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    collegename varchar(30) NOT NULL,
    state varchar(25) NOT NULL,
    FOREIGN KEY (state) REFERENCES api_state (statename)
);
CREATE UNIQUE INDEX sqlite_autoindex_api_college_1 ON api_college (collegename);
CREATE INDEX api_college_9ed39e2e ON api_college (state)

在配置postgress数据库并在浏览器上访问django admin后得到的错误:: 我首先添加状态UP 然后,当我选择州为Up并将大学添加为testcollege时,我收到此错误::

    create table api_college
(
    id serial not null
        constraint api_college_pkey
            primary key,
    collegename varchar(30) not null,
    statename_id integer not null
)
;

create index api_college_b291eb83
    on api_college (statename_id)
;

create table api_state
(
    id serial not null
        constraint api_state_pkey
            primary key,
    statename varchar(25) not null
)
;

alter table api_college
    add constraint api_college_statename_id_7e126c2d_fk_api_state_id
        foreign key (statename_id) references api_state
            deferrable initially deferred
;

0 个答案:

没有答案