如何在 Django 中使用 sql 文件创建 postgressql 数据库?请指导我一步一步。我有 sql 如下
how to create postgresql database using sql file in django? please guide me step by step. I have sql as follows
这里是 sql 我想转换成 postgresql 数据库的文件代码
CREATE TABLE banks (
name character varying(49),
id bigint NOT NULL
);
--
-- Name: branches; Type: TABLE; Schema: public; Owner: siva; Tablespace:
--
CREATE TABLE branches (
ifsc character varying(11) NOT NULL,
bank_id bigint,
branch character varying(74),
address character varying(195),
city character varying(50),
district character varying(50),
state character varying(26)
);
--
-- Name: bank_branches; Type: VIEW; Schema: public; Owner: siva
--
CREATE VIEW bank_branches AS
SELECT branches.ifsc,
branches.bank_id,
branches.branch,
branches.address,
branches.city,
branches.district,
branches.state,
banks.name AS bank_name
FROM (branches
JOIN banks ON ((branches.bank_id = banks.id)));
然后有 120k 行输入使用标准输入
COPY banks (name, id) FROM stdin;
COPY branches (ifsc, bank_id, branch, address, city, district, state) FROM stdin;
我用的是django3.2,psycopg2.8,postgrsql13,windows10
ERROR: character with byte sequence 0x90 in encoding "WIN1252" has no equivalent in encoding "UTF8"
对于这个错误,我将文件转换为 ANSI 并在记事本中删除了所有在 UTF8 中不可见的 ANSI 字符。
然后 运行 按照来自 psql 的命令 shell
psql -h localhost -d databasename -U username -f "c://path_to_file.sql"
这里是 sql 我想转换成 postgresql 数据库的文件代码
CREATE TABLE banks (
name character varying(49),
id bigint NOT NULL
);
--
-- Name: branches; Type: TABLE; Schema: public; Owner: siva; Tablespace:
--
CREATE TABLE branches (
ifsc character varying(11) NOT NULL,
bank_id bigint,
branch character varying(74),
address character varying(195),
city character varying(50),
district character varying(50),
state character varying(26)
);
--
-- Name: bank_branches; Type: VIEW; Schema: public; Owner: siva
--
CREATE VIEW bank_branches AS
SELECT branches.ifsc,
branches.bank_id,
branches.branch,
branches.address,
branches.city,
branches.district,
branches.state,
banks.name AS bank_name
FROM (branches
JOIN banks ON ((branches.bank_id = banks.id)));
然后有 120k 行输入使用标准输入
COPY banks (name, id) FROM stdin;
COPY branches (ifsc, bank_id, branch, address, city, district, state) FROM stdin;
我用的是django3.2,psycopg2.8,postgrsql13,windows10
ERROR: character with byte sequence 0x90 in encoding "WIN1252" has no equivalent in encoding "UTF8"
对于这个错误,我将文件转换为 ANSI 并在记事本中删除了所有在 UTF8 中不可见的 ANSI 字符。
然后 运行 按照来自 psql 的命令 shell
psql -h localhost -d databasename -U username -f "c://path_to_file.sql"