gpt4 book ai didi

android - SQLDelight 迁移

转载 作者:行者123 更新时间:2023-12-04 23:49:11 30 4
gpt4 key购买 nike

我正在尝试在 SQLDelight 的表中添加更多列。我做了一个迁移文件 1.sqm .在迁移文件中,它给出了找不到表的错误。 enter image description here
我的 build.gradle.kts:

sqldelight {
database("AppDatabase") {
packageName = "com.jetbrains.handson.kmm.shared.cache"
schemaOutputDirectory = file("shared/src/commonMain/sqldelight/com/jetbrains/handson/kmm/shared/cache/AppDatabase.sq")
migrationOutputDirectory = file("shared/src/commonMain/sqldelight/migrations/1.sqm")
migrationOutputFileFormat = ".sqm"
schemaOutputDirectory
deriveSchemaFromMigrations = true
}
}
创建表语句:
CREATE TABLE pos_orders(id INTEGER AS Int PRIMARY KEY, orderId INTEGER AS Int , dateandtime TEXT, restaurant_id INTEGER AS Int, restaurant_name TEXT, deliveryType_description TEXT, paymentType_description TEXT, totalAmount REAL AS Float,
process_order INTEGER AS Int, pos_accept INTEGER AS Int, pos_printed INTEGER AS Int, status INTEGER AS Int, prep_time INTEGER AS Int, desired_delivery_time TEXT, restaurant_address TEXT, customerNo TEXT, title TEXT, firstName TEXT, lastName TEXT,company TEXT, street TEXT, houseNo TEXT, zip TEXT, city TEXT, state TEXT,floor TEXT, bezirk TEXT, bellname TEXT, email TEXT, phoneNo TEXT, fax TEXT, taxAmount REAL AS Float, total REAL AS Float , deliverycharges REAL AS Float,
deliveryType INTEGER AS Int, paymentType INTEGER AS Int, comment TEXT, order_note TEXT, sender TEXT, cancelation_cause TEXT, demo_order INTEGER AS Int, orderDate TEXT, updated TEXT);

最佳答案

sqldelight {
database("AppDatabase") {
packageName = "com.jetbrains.handson.kmm.shared.cache"
schemaOutputDirectory = file("com.jetbrains.handson.kmm.shared.cache")
migrationOutputDirectory = file("com.jetbrains.handson.kmm.shared.cache")
deriveSchemaFromMigrations = true
verifyMigrations = true
}
}
把 gradle.build 改成上面那个
然后
在路径中,与我使用两个文件夹 所写的完全一样sqldelight
shared/src/commonMain/sqldelight/com/jetbrains/handson/kmm/shared/cache/sqldelight

在 sqldelight 文件夹中放置所有数据库文件 AppDatabase.sq、1.sqm、2.sqm ... 等等
诀窍就在这里
在 AppDatabase.sq 只放数据库查询。
AppDatabase 应该看起来像
getAll:
SELECT * FROM pos_orders;

deleteAll:
DELETE FROM pos_orders;
并创建另一个 1.sqm 来放置您的原始表格并创建 2.sqm 来放置您的迁移。
1.sqm 应该看起来像
CREATE TABLE pos_orders(id INTEGER AS Int PRIMARY KEY, orderId INTEGER AS Int , dateandtime TEXT, restaurant_id INTEGER AS Int, restaurant_name TEXT, deliveryType_description TEXT, paymentType_description TEXT, totalAmount REAL AS Float,
process_order INTEGER AS Int, pos_accept INTEGER AS Int, pos_printed INTEGER AS Int, status INTEGER AS Int, prep_time INTEGER AS Int, desired_delivery_time TEXT, restaurant_address TEXT, customerNo TEXT, title TEXT, firstName TEXT, lastName TEXT,company TEXT, street TEXT, houseNo TEXT, zip TEXT, city TEXT, state TEXT,floor TEXT, bezirk TEXT, bellname TEXT, email TEXT, phoneNo TEXT, fax TEXT, taxAmount REAL AS Float, total REAL AS Float , deliverycharges REAL AS Float,
deliveryType INTEGER AS Int, paymentType INTEGER AS Int, comment TEXT, order_note TEXT, sender TEXT, cancelation_cause TEXT, demo_order INTEGER AS Int, orderDate TEXT, updated TEXT);
2.sqm 应该看起来像
ALTER TABLE pos_orders ADD COLUMN year INTEGER ;

关于android - SQLDelight 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66968873/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com