我已经创建了数据库连接,还创建了一个模型(用户),但是当我尝试生成示例数据时,只是为了确保在mysql工作台数据库中创建了表。它抛出一个错误。 以下是我所做的图像。
Connection.ts:
import { Sequelize } from 'sequelize';
const sequelize = new Sequelize('localDB', 'root', '', {
host: 'localhost',
dialect: 'mssql' /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch((err: any) => {
console.error('Unable to connect to the database:', err);
});
export default sequelize;
User.ts
import { DATE, STRING, BOOLEAN } from 'sequelize';
import sequelize from '../config/databaseConnection';
const User = sequelize.define('user', {
id: {
type: STRING, autoIncrement: true, primaryKey: true, allowNull:
false
},
firstName: {
type: STRING, allowNull: false,
},
lastName: {
type: STRING, allowNull: false,
},
isActive: {
type: BOOLEAN
},
createdAt: DATE,
updatedAt: DATE
});
User.sync({}).then(() => {
return User.create({})
});
export default User;