We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
创建了 User 模型,以及 Profile 模型。
给 user 模型和 profile 模型添加一对一关系。
在 已有模型 的情况之下,如何能通过 sequelize-cli 的 migrate 功能实现添加关联关系的操作呢?
我想我知道如何在 model 层面里进行关联关系的添加,但是目的是 「版本管理」 嘛。
// app/model/user.js ... User.associate = () => User.hasOne(Profile); ... // app/model/profile.js ... Profile.associate = () => Profile.belongsTo(User); ...
// app/model/user.js module.exports = app => { const { STRING} = app.Sequelize; const User = app.model.define('User', { id: { type: INTEGER, primaryKey: true, autoIncrement: true, }, username: STRING, password: STRING, }); return User; };
// app/model/profile.js module.exports = app => { const { STRING, INTEGER } = app.Sequelize; const Profile = app.model.define('Profile', { description: STRING, user_id: INTEGER, }); return Profile; };
The text was updated successfully, but these errors were encountered:
大佬可以告诉小弟,改了model的外键之后,生成的sql语句在哪里?怎么执行呢?怎么通过cli变更到数据库呢??? 看了无数文档,始终没有找到办法。
Sorry, something went wrong.
No branches or pull requests
目前状态
创建了 User 模型,以及 Profile 模型。
需求
给 user 模型和 profile 模型添加一对一关系。
在 已有模型 的情况之下,如何能通过 sequelize-cli 的 migrate 功能实现添加关联关系的操作呢?
我想我知道如何在 model 层面里进行关联关系的添加,但是目的是 「版本管理」 嘛。
Models
The text was updated successfully, but these errors were encountered: