渡槽框架不产生迁移

Aqueduct framework not generating migrations

我正在尝试使用命令从模型生成迁移 - "aqueduct db generate"。

这是 lib > model 下的模型 "request.dart"(我还有其他模型,它们已经顺利迁移):

import 'package:dbapi/dbapi.dart';

class Request extends ManagedObject<_Request> implements _Request {}

class _Request {

@managedPrimaryKey

int index;

String description;

}

然而,它正在创建一个空迁移,因为它无法识别新模型-"Request"。以下是 "aqueduct db generate"

的输出
-- Aqueduct CLI Version: 2.5.0+1
-- Aqueduct project version: 2.5.0+1
-- Replaying migration files...
Replaying version 1
Replaying version 2
Replaying version 3
 -- The following ManagedObject<T> subclasses were found:
     Question
     UserProfile

* If you were expecting more declarations, ensure the files are visible in the application library file.

  -- Created new migration file (version 4).

注意:新模型 "request.dart" 与我可以迁移的先前模型具有相同的文件权限。

还有其他人 运行 遇到同样的问题吗?感谢您的帮助!

文件 request.dart 必须由您的应用程序的库文件导入(直接或传递)。在您的情况下,这是 dbapi.dart

但是,您不太可能直接在库文件中导入 request.dart。相反,您的库文件已经导入了您的 RequestSink 文件,该文件必须导入应用程序使用的任何控制器文件,而这些文件必须导入它们使用的任何模型。

这里可能的情况是您尚未在代码中使用此 class - 一旦您开始在控制器或服务中使用它,迁移生成工具就会看到它。否则,您可以直接从您的请求接收器文件中导入它。

正如 Joe Conway 所说,我必须将 ManagedObject 子类导入到我的控制器中:

import 'package:my_project/model/my_model.dart';

比运行

aqueduct db generate

创建了正确的迁移文件。无论如何,我最终打算在控制器中使用托管对象,但我还没有,我想先生成迁移文件。