postgresql - 如何在 psql 客户端中创建表?
问题描述
我有一个可以使用 postico 访问的现有数据库,并且我想将结构迁移到一个只能使用 psql 访问的新数据库。
Postico 给出了重新创建表的 SQL
-- DDL generated by Postico 1.5.8 -- Not all database features are supported. Do not use for backup. -- Table Definition ---------------------------------------------- CREATE TABLE "Datas" ( id integer DEFAULT nextval('"Data_id_seq"'::regclass) PRIMARY KEY, DataLabel character varying(255) NOT NULL, DataValue character varying(255), "createdAt" timestamp with time zone NOT NULL, "updatedAt" timestamp with time zone NOT NULL ); -- Indices ------------------------------------------------------- CREATE UNIQUE INDEX "Data_pkey" ON "Datas"(id int4_ops); CREATE INDEX datas_id ON "Datas"(id int4_ops);
但是,如果我尝试在 psql 客户端中运行创建表,则会收到错误消息
relation "Datas_id_seq" does not exist
如何迁移表结构?我需要手动创建关系吗?如果是这样怎么办?
解决方案
您需要先创建序列"Data_id_seq"
:
create sequence "Data_id_seq";
但该列可能serial
最初定义为:
CREATE TABLE "Datas" (
id serial PRIMARY KEY,
DataLabel character varying(255) NOT NULL,
DataValue character varying(255),
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL
);
推荐阅读
- javascript - 用任何令牌交换任何令牌 - Sniper Bot Javascript - - pancakeswap、quickswap、caffeswap
- python - picamera:捕捉黑色图像
- c++ - 在 C++ 中解析 .wav 文件的数据夹盘
- filter - 在 UA 查询资源管理器中过滤 OR
- reactjs - 有没有办法减小 create-react-app 创建的 main.chunk.js 的大小?还是将其分成各种较小的?
- timer - STM32:如何配置定时器以在正交编码器模式下每次增量触发中断?
- php - 更新时如何在mysql SET中插入变量?
- python - 在python中旋转二维数组的问题
- json - pySpark - 在插入数据库之前将整个数据框列转换为 JSON 对象
- amazon-web-services - 如何创建加入中未找到的项目计数?