Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Sequelize迁移工具找不到config.json中定义的架构_Postgresql_Docker_Sequelize.js_Database Schema_Sequelize Cli - Fatal编程技术网

Postgresql Sequelize迁移工具找不到config.json中定义的架构

Postgresql Sequelize迁移工具找不到config.json中定义的架构,postgresql,docker,sequelize.js,database-schema,sequelize-cli,Postgresql,Docker,Sequelize.js,Database Schema,Sequelize Cli,当从postgres图像启动docker容器时,它只会在数据库下创建一个公共模式。这是我的背景 postgres: container_name: postgres image: postgres:latest ports: - "${DB_PORT}:5432" environment: - POSTGRES_USER=${DB_USER}

当从postgres图像启动docker容器时,它只会在数据库下创建一个公共模式。这是我的背景

postgres:
        container_name: postgres
        image: postgres:latest
        ports:
            - "${DB_PORT}:5432"
        environment:
            - POSTGRES_USER=${DB_USER}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
            - POSTGRES_DB=${DB_NAME}
我的解决办法是

// 111111-create-schema.js
await queryInterface.createSchema('custom');

// 222222-create-user.js
await queryInterface.createTable('Users', {}, {schema: 'custom'}
当我运行
npx sequelize cli db:migrate
时,我确实在自定义模式中看到了我的用户表。但是,存储迁移的sequelizeMeta表位于PUBLICshema中

我还尝试在config.json中添加
schema:'custom'
。但是,当我运行db:migrate时,我得到了一个“未找到自定义架构”错误。我假设在那个时候,我的迁移脚本在试图定位这个自定义模式之前还没有运行

然后我尝试在pgadmin中手动创建模式。然后我看到我的user和sequelizeMeta表都在这个自定义模式中

我想知道如何让postgres docker容器预创建模式,就像它使用postgres_DB环境变量预创建数据库一样?差不多

postgres:
        container_name: postgres
        image: postgres:latest
        ports:
            - "${DB_PORT}:5432"
        environment:
            - POSTGRES_USER=${DB_USER}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
            - POSTGRES_DB=${DB_NAME}
            - POSTGRES_SCHEMA=${DB_SCHEMA} <---------------
postgres:
容器名称:postgres
图片:postgres:最新
端口:
-“${DB_PORT}:5432”
环境:
-POSTGRES_USER=${DB_USER}
-POSTGRES_PASSWORD=${DB_PASSWORD}
-POSTGRES_DB=${DB_NAME}

-POSTGRES_SCHEMA=${DB_SCHEMA}当您创建sequelize连接时,在定义对象上说出您的模式,如下所示:

const sequelize = new Sequelize(database, username, password,
{
   host, dialect, port, omitNull: true,
   define: {
     schema: "your-schema"
     timestamps: true,
     underscored: true
   },
   ...
 })

您可以创建一个脚本,该脚本可以在容器启动时作为容器的命令执行,并且该脚本可以在postgres中预先创建模式。