vapor 3,流畅的模型不会在数据库中创建原始的
vapor 3, fluent model doesn't create raw in DB
我正在尝试创建一个模型 (MySQLStringModel
) 并为其设置一个 ID(String ?
类型)。控制台中没有错误或任何其他消息,并且 save(on: req)
工作成功,但模型没有出现在数据库的 Table 中。有什么问题吗?
func create(_ req: Request, person: Person) throws -> Future<Person> {
return Person(id: person.id, name: person.name).save(on: req)
}
P.s.:当我使用带有 Int?
id 的 MySQLModel 时一切正常,我没有直接设置这个 id(它设置为自动自动增量 )
方法中的问题
.save(on: req)
如文档中所述:
Saves the model, calling either create(...) or update(...) depending on whether the model already has an ID.
If you need to create a model with a pre-existing ID, call create instead.
所以,方法 .create(on: req)
帮助了我,新的 raw 出现在 table。
我正在尝试创建一个模型 (MySQLStringModel
) 并为其设置一个 ID(String ?
类型)。控制台中没有错误或任何其他消息,并且 save(on: req)
工作成功,但模型没有出现在数据库的 Table 中。有什么问题吗?
func create(_ req: Request, person: Person) throws -> Future<Person> {
return Person(id: person.id, name: person.name).save(on: req)
}
P.s.:当我使用带有 Int?
id 的 MySQLModel 时一切正常,我没有直接设置这个 id(它设置为自动自动增量 )
方法中的问题
.save(on: req)
如文档中所述:
Saves the model, calling either create(...) or update(...) depending on whether the model already has an ID.
If you need to create a model with a pre-existing ID, call create instead.
所以,方法 .create(on: req)
帮助了我,新的 raw 出现在 table。