如果您要啓用Sequelize
日誌記錄,您會看到在「同步」階段和創建表格之後,Sequelize
執行SHOW INDEX FROM table
查詢。問題是 - 爲什麼?爲什麼會將問題「從table表中顯示索引」加入問題?
更具體地講,這裏是我執行的代碼:
var Sequelize = require('sequelize');
var connection = new Sequelize('demo_schema', 'root', 'password');
var Article = connection.define('article', {
slug: {
type: Sequelize.STRING,
primaryKey: true
},
title: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
body: {
type: Sequelize.TEXT
}
}, {
timestamps: false
});
connection.sync({
force: true,
logging: console.log
}).then(function() {
// TODO
});
這裏是控制檯輸出:
Executing (default): DROP TABLE IF EXISTS `articles`;
Executing (default): DROP TABLE IF EXISTS `articles`;
Executing (default): CREATE TABLE IF NOT EXISTS `articles` (`slug` VARCHAR(255) , `title` VARCHAR(255) NOT NULL UNIQUE, `body` TEXT, UNIQUE `articles_title_unique` (`title`), PRIMARY KEY (`slug`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `articles`
非常感謝您的細化分解!現在我們有一個完全清晰的畫面。 – alecxe
不客氣!我很高興能夠提供幫助。 –
它是否刪除ORM中未定義的索引? – elmigranto