我正在使用express.js構建Web服務,並使用Postgres數據庫進行Sequilize。使用sequelize-cli db:seed,在訪問Postgres時忽略模式
數據庫在schema'schema1'下面保存着一個表'country'。表'國家'具有字段'名稱','isoCode'。
創建一個種子文件,在表'country'內插入一個國家列表。
種子文件看起來像:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(
'country',
[
{
"name":"Afghanistan",
"isoCode":"AF"
},
{
"name":"Åland Islands",
"isoCode":"AX"
},
{
"name":"Albania",
"isoCode":"AL"
},
{
"name":"Algeria",
"isoCode":"DZ"
},
{
"name":"American Samoa",
"isoCode":"AS"
},
{
"name":"Andorra",
"isoCode":"AD"
}
],
{
schema : 'schema1'
}
);
},
down: function (queryInterface, Sequelize) {
}
};
在運行種子我得到這個錯誤:
node_modules/sequelize-cli/bin/sequelize --url postgres://user:[email protected]:5432/database db:seed
Sequelize [Node: 0.12.6, CLI: 2.0.0, ORM: 3.11.0, pg: ^4.4.2]
Parsed url postgres://user:*****@localhost:5432/database
Starting 'db:seed'...
Finished 'db:seed' after 165 ms
== 20151029161319-Countries: migrating =======
Unhandled rejection SequelizeDatabaseError: relation "country" does not exist
at Query.formatError (node_modules/sequelize/lib/dialects/postgres/query.js:437:14)
at null.<anonymous> (node_modules/sequelize/lib/dialects/postgres/query.js:112:19)
at emit (events.js:107:17)
at Query.handleError (node_modules/pg/lib/query.js:108:8)
at null.<anonymous> (node_modules/pg/lib/client.js:171:26)
at emit (events.js:107:17)
at Socket.<anonymous> (node_modules/pg/lib/connection.js:109:12)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
我想我被困在此我。我會很感激任何提供的幫助/指導等。
謝謝你的時間。
什麼是DB用戶的search_path?也許它不包括'schema1' –
感謝您的回覆。執行: 顯示SEARCH_PATH 結果是: 「$用戶」,公共 –
然後,當然不合格的表的名字不會被解析爲'schema1'。您可能需要更改用戶的搜索路徑以包含'schema1',教您的圖書館使用模式來限定表格,或者教您的圖書館如何在連接後動態更改搜索路徑 –