0
任何一個知道如何在sequelize播種機自定義查詢
我已經嘗試了兩種方式自定義選擇查詢,但沒有一個工作
首次嘗試
up: function(queryInterface, Sequelize) {
return queryInterface.sequelize.query(
'SELECT * FROM "Users" WHERE username = "admin"',
{ type: queryInterface.sequelize.QueryTypes.SELECT }
).then(function(users) {});
},
,然後有錯誤
SequelizeDatabaseError: column "admin" does not exist
我不明白nd爲什麼管理員在這裏列?
第二次嘗試
return queryInterface.sequelize.query('SELECT * FROM "Users" WHERE username = :admin', {
replacement: {
admin: 'admin'
},
type: queryInterface.sequelize.QueryTypes.SELECT
}).then(function(users) {
});
下面出錯
SequelizeDatabaseError: syntax error at or near ":"
第三次嘗試
return queryInterface.sequelize.query(
'SELECT * FROM "Users" WHERE username = ' admin '',
{type: queryInterface.sequelize.QueryTypes.SELECT})
.then(function(users) { })
錯誤:
SyntaxError: missing) after argument list
修訂
第四次嘗試
return queryInterface.sequelize.query(
'SELECT * FROM Users WHERE username = "admin"',
{ type: queryInterface.sequelize.QueryTypes.SELECT }
).then(function(users) {});
另一個錯誤出現:
SequelizeDatabaseError: relation "Users" does not exist
queryInterface.sequelize.query('SELECT * FROM "Users"')
工作沒有任何錯誤。我覺得這裏的問題出在哪裏查詢
它的駕駛我瘋狂:)
感謝您的幫助提前!
在第一次嘗試,你應該刪除各地用戶 – Shivam
報價它不工作。查看我更新的Shivam :) –
除非您想創建/使用標識符,否則請勿在查詢中使用雙引號。你的查詢應該寫成:'「SELECT * FROM Users WHERE username ='admin'」' –