【问题标题】:SQL script does not see databaseSQL 脚本看不到数据库
【发布时间】:2021-10-16 15:27:43
【问题描述】:

我想更改表中的一些名称。我正在使用 Flyway,所以我使用迁移。 我想更改表中的名称,但脚本看不到表。数据库已docker化。

我想改变这个:

 create table if not exists document_entity
 (
    document_id varchar
    constraint document_entity_document_id
    not null primary key,
    document_file varchar not null
 );

进入这个:

 alter table document_entity
   rename to documents;
 alter table document_entity
   rename column document_id to id;
 alter table document_entity
   rename column document_file to file;

我还必须从第一个表更改关系,但不知道如何写。

【问题讨论】:

  • 嗯,在您已经document_id重命名为id之后,您正在尝试重命名它。当然 document_id 在那个时候已经找不到了,它现在被称为 id
  • 我在写帖子时弄错了,编辑了它

标签: postgresql migration flyway


【解决方案1】:

您在第一个查询中修改了 document_entity 的表名。第二个和第三个查询不能改变 document_entity 而是文档,因为documents_entity 已经不存在了。

alter table document_entity rename to documents; 
alter table documents rename column document_id to id; 
alter table documents rename column document_file to file;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多