node.jsでクイズアプリを作成しているのですが、データをpostgresに書き出すことができません。
PORT=8000 npm startを実行するとconsole上にエラー出力されます。
初歩的なエラーなのかもしれないですが、ご教授くださいますと幸いです。
よろしくお願い申し上げます。
下記がエラーです。
Unhandled rejection SequelizeDatabaseError: foreign key constraint "choices_questionId_fkey" cannot be implemented
**app.js** // モデルの読み込み var User = require('./models/user'); var Quiz = require('./models/quiz'); var Question = require('./models/question'); var Choice = require('./models/choice'); User.sync().then(() => { Quiz.belongsTo(User, { foreignKey: 'createdBy' }); Quiz.sync().then(() => { Question.belongsTo(Quiz, { foreignKey: 'quizId' }); Question.sync() .then(() => { Choice.belongsTo(Question, { foreignKey: 'questionId' }) Choice.sync(); }); }); });
choice.js(モデル) 'use strict'; const loader = require('./sequelize-loader'); const Sequelize = loader.Sequelize; const Choice = loader.database.define('choices', { choiceId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false }, choice: { type: Sequelize.TEXT, allowNull: false }, questionId: { type: Sequelize.UUID, allowNull: false } }, { freezeTableName: true, timestamps: false, indexes: [ { fields: ['questionId'] } ] }); module.exports = Choice; コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/17 01:57