
[英]React Native can't find child elements when accessible is true
[英]Can't run migrations with migrationsRun: true
我有一个带有 SQLite 数据库和 TypeORM 设置的 React Native + Expo 项目。 我正在尝试运行一个迁移,它应该通过将migrationsRun数据源配置选项设置为true在应用程序启动时将一个isPrivate列添加到现有的Note表中。 但它不起作用。 似乎 TypeORM 根本看不到迁移,即使路径是正确的。
如果 Note 实体定义了 isPrivate 列并且我尝试使用存储库实例中的find方法,则会抛出以下错误:
no such column: Note.isPrivate (code 1 SQLITE_ERROR): , while compiling: SELECT "Note"."id" AS "Note_id", "Note"."title" AS "Note_title", "Note"."details" AS "Note_details", "Note"."isPrivate" AS "Note_isPrivate", "Note"."folderId" AS "Note_folderId" FROM "note" "Note"
这是data-source.ts文件:
import "reflect-metadata";
import { DataSource } from "typeorm";
import * as sqlitedriver from 'expo-sqlite';
import Folder from './entities/Folder.model.ts';
import Note from './entities/Note.model.ts';
const AppDataSource = new DataSource({
driver: sqlitedriver,
database: 'app_db',
type: 'expo',
migrationsRun: true,
entities: [Folder, Note],
migrations: ['migrations/*.ts'],
});
AppDataSource.initialize().then(() => {
console.log("Data Source has been initialized!");
}).catch((err) => {
console.error("Error during Data Source initialization", err.message);
});
export default AppDataSource;
迁移文件:
import { MigrationInterface, QueryRunner } from "typeorm";
import { TableColumn } from "typeorm";
export class AddIsPrivateColumn1684782594104 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
"Note",
new TableColumn({
name: "isPrivate",
type: "boolean",
}),
);
};
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn("Note", "isPrivate");
};
};
如何运行迁移? 数据源配置有问题吗?
好的,所以我想我解决了它。 我的问题是在数据源配置 object 中列出了迁移。出于某种原因,我无法将它们指定为路径字符串,因此我直接导入了迁移类并将它们添加到migrations
数组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.