使用sequelize执行多对多迁移

时间:2017-07-10 01:08:45

标签: mysql node.js orm sequelize-cli

这是我第一次使用sequelize,我希望运行多对多的迁移。这是我的模型的设置:

'use strict'; module.exports = function(sequelize, DataTypes) { var Collection = sequelize.define('Collection', { title: DataTypes.STRING }, { classMethods: { associate: function(models) { // associations can be defined here Collection.belongsToMany(Post, { through: CollectionPost, foreignKey: 'collection_id' }); } } }); return Collection; };

models/post.js

'use strict'; module.exports = function(sequelize, DataTypes) { var Post = sequelize.define('Post', { title: DataTypes.STRING }, { classMethods: { associate: function(models) { // associations can be defined here Post.belongsToMany(Collection, { through: CollectionPost, foreignKey: 'post_id' }); } } }); return Post; };

sync

我知道sequelize有const models = require('../models'); function test() { return models.sequelize.sync((err, response) => { console.log(err); console.log('.........'); console.log(response); }); } test(); 方法可以将模型与迁移同步。但是我只想同步一次,因此我写了这个小脚本:

CollectionPost

但是,这不是创建# Step 2: create placeholders for input X (Features) and label Y (binary result) X = tf.placeholder(tf.float32, shape=[None, 9], name="X") Y = tf.placeholder(tf.float32, shape=[None,2], name="Y") # Step 3: create weight and bias, initialized to 0 w = tf.Variable(tf.truncated_normal([9, 2]), name="weights") b = tf.Variable(tf.zeros([1,2]), name="bias") # Step 4: logistic multinomial regression / softmax score = tf.matmul(X, w) + b # Step 5: define loss function entropy = tf.nn.softmax_cross_entropy_with_logits(logits=score, labels=Y, name="entropy") regularizer = tf.nn.l2_loss(w) loss = tf.reduce_mean(entropy + BETA * regularizer, name="loss") # Step 6: using gradient descent optimizer = tf.train.GradientDescentOptimizer(learning_rate=LEARNING_RATE).minimize(loss) # Step 7: Prediction Y_predicted = tf.nn.softmax(tf.matmul(X, w) + b) correct_prediction = tf.equal(tf.argmax(Y_predicted,1), tf.argmax(Y,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 表。我错过了什么?

0 个答案:

没有答案