我尝试使用 Diesel 和 SQLite 数据库创建迁移,但继续收到以下错误:
Diesel only supports tables with primary keys. Table cycles has no primary key
但是,我已将表缩减为只有一个主键。这是我的整个
up.sql
文件:
CREATE TABLE cycles (
id INTEGER PRIMARY KEY,
);
为了完整起见,这是我的迁移命令:
diesel migration run --database-url ~/.config/cycles/dev.sqlite
如果有帮助,这是我的
diesel.toml
:
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src-tauri/src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId"]
[migrations_directory]
dir = "migrations"
我错过了什么?
提供的迁移不会重现您问题中的错误。对我来说,应用迁移失败并显示以下错误消息:
$ cat migrations/2024-01-22-122221_test_stackoverflow/up.sql
-- Your SQL goes here
CREATE TABLE cycles (
id INTEGER PRIMARY KEY,
);
$ diesel migration run --database-url /tmp/tests
Running migration 2024-01-22-122221_test_stackoverflow
Failed to run 2024-01-22-122221_test_stackoverflow with: near ")": syntax error
修复错误消息中指出的语法错误后
diesel
正确生成以下schema.rs
文件:
// @generated automatically by Diesel CLI.
diesel::table! {
cycles (id) {
id -> Nullable<Integer>,
}
}