database - 在 knex 迁移:上,table.foreign 未显示在终端的实际表上
问题描述
我已经设置 knex 迁移来创建两个表
export async function up(knex: Knex): Promise<void> {
const table1 = await knex.schema.hasTable('users');
if (!table1) {
await knex.schema.createTable('users', (table) => {
table.increments("id").primary();
table.string("username");
table.string("email");
table.string("password");
table.string("role");
table.timestamp("created_at");
table.timestamp("updated_at");
table.timestamp("logged_at");
});
}
const table2 = await knex.schema.hasTable('usersloc');
if (!table2) {
await knex.schema.createTable('usersloc', (table) => {
table.increments("locid");
table.string("lat");
table.string("lng")
table.foreign("userid");
});
}
}
但是,当我执行select * from usersloc;
, userid
in usersloc 时,无处可寻。
我的意图是将其引用到id
“用户”表中。
知道发生了什么吗?
解决方案
找到解决方案 - 看起来 UUID 需要在两个表上都有一个 .unique() 引用。我的猜测是,尽管 UUID 可能需要数十亿年才能有 1% 的碰撞机会,但它仍然不是唯一 ID,因此需要 .unique() 引用。
推荐阅读
- r - 使用显示 NA 值的 tab_cells 在 R 中创建交叉表
- css - 如何在 Gmail 附件中实现“悬停”?
- julia - 当您首先不知道数组的尺寸时如何在 Julia 中初始化数组
- list - 如何从列表列表的某些元素之间的组合生成多个列表(在java或C中)
- android - 出现 qr scannig Fragment 但未进行扫描
- wordpress - 使用 Wordpress 身份验证解析平台
- android - AlarmManager setRepeating() 在不正确的时间触发
- python-3.x - 如何编码具有高基数的列?
- python - 如何纠正错误:迭代器应该返回字符串,而不是字节(您是否以文本模式打开文件?)在 csv e netcdf 文件中?
- asp.net-core - Progressive Web App - 如何将图像/文件存储到手机的图库中?