Vapor with Postgres - table 没有做好准备
Vapor with Postgres - table is not getting prepared
我的项目中有 3 个 Model
个对象。
drop.preparations.append(Club.self)
drop.preparations.append(ClubPlayers.self)
drop.preparations.append(Player.self)
出于某种原因,俱乐部 table 未创建。这是我的 prepare
方法:
static func prepare(_ database: Database) throws {
try database.create(Club.tableName, closure: { club in
club.id()
club.string(Club.nameColumn)
club.string(Club.urlColumn)
})
}
它的构建与我的其他模型完全相同,但它是唯一一个没有被创建的模型。我没有收到任何警告或错误。
我正在使用 Swift 3.1.1、vapor 1.5 和 vapor-toolbox 2
我的解决方案是:从 'fluent' table 中删除 'Club' 行。然后 运行 vapor run prepare
起作用了。
还有其他选项:
- 使用迁移。 https://vapor.github.io/documentation/fluent/model.html#preparations-as-migrations
- 使用 psql
ADD COLUMN
命令。 http://www.postgresqltutorial.com/postgresql-add-column/
- 我没有尝试 tanner0101 建议,但听起来很有趣
我的项目中有 3 个 Model
个对象。
drop.preparations.append(Club.self)
drop.preparations.append(ClubPlayers.self)
drop.preparations.append(Player.self)
出于某种原因,俱乐部 table 未创建。这是我的 prepare
方法:
static func prepare(_ database: Database) throws {
try database.create(Club.tableName, closure: { club in
club.id()
club.string(Club.nameColumn)
club.string(Club.urlColumn)
})
}
它的构建与我的其他模型完全相同,但它是唯一一个没有被创建的模型。我没有收到任何警告或错误。 我正在使用 Swift 3.1.1、vapor 1.5 和 vapor-toolbox 2
我的解决方案是:从 'fluent' table 中删除 'Club' 行。然后 运行 vapor run prepare
起作用了。
还有其他选项:
- 使用迁移。 https://vapor.github.io/documentation/fluent/model.html#preparations-as-migrations
- 使用 psql
ADD COLUMN
命令。 http://www.postgresqltutorial.com/postgresql-add-column/ - 我没有尝试 tanner0101 建议,但听起来很有趣