javascript - node.js - UnhandledPromiseRejectedWarning:SQLITE_ERROR:表鞋没有名为“颜色”的列
问题描述
当我尝试使用正文中的外键将寄存器发布到“color_shoes”时,我创建了一个带有主键“id”的表“shoes”,以及一个以“Shoes”中的“id”作为外键的表“color_shoes”根据我的请求,我收到了这个错误:“UnhandledPromiseRejectedWarning: SQLITE_ERROR: table shoes has no column named 'color'”
这是在表“color_shoes”中创建寄存器的控制器功能
module.exports = {
async create(request, response) {
const { color, shoe_id } = request.body;
const color_id = crypto.randomBytes(4).toString('HEX');
await connection('shoes').insert({
color_id,
color,
shoe_id,
});
return response.json({ color_id });
}
}
这是到表“color_shoes”的迁移:
exports.up = function(knex) {
return knex.schema.createTable('shoes_colors', function (table) {
table.string('color_id').primary();
table.string('color').notNullable();
table.string('shoe_id').notNullable();
table.foreign('shoe_id').references('id').inTable('shoes');
})
};
exports.down = function(knex) {
return knex.schema.dropTable('shoes_colors');
};
这是迁移到表“鞋子”:
exports.up = function(knex) {
return knex.schema.createTable('shoes', function (table) {
table.string('id').primary();
table.string('model').notNullable();
table.string('sponsor').notNullable();
})
};
exports.down = function(knex) {
return knex.schema.dropTable('shoes');
};
解决方案
推荐阅读
- django - 无法理解 SerializerRelated 字段 (CustomSlugRelatedField)
- c# - 您可以对 System.IO 命名空间及其类(文件信息、目录等)做什么?(简单的术语)
- powerbi - Power BI,计算不同的空值
- matrix - 如何右移矩阵的每一行?
- c# - c#列表比较
- flutter - 修剪和删除飞镖中字符串开头和结尾的特定字符
- javascript - 在 Google Apps 脚本中执行节点 JS 代码
- javascript - 代码仅在编辑模式下工作,而不是在实时视图中
- reactjs - 使用 spfx 的 Sharepoint 列表中的项目计数
- nuget - 是否有用于 UNO 的 UWP nuget 的 Telerik UI?