我的服务器可以打开,但我的数据库不创建表用户,我不知道我的代码的问题,我所做的是根据蒸汽文件。
我在config+setup.swift中添加了preparation和addprovider
日志:
The current hash key "0000000000000000" is not secure.
Update hash.key in Config/crypto.json before using in production.
Use `openssl rand -base64 <length>` to generate a random string.
The current cipher key "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" is not secure.
Update cipher.key in Config/crypto.json before using in production.
Use `openssl rand -base64 32` to generate a random string.
[2018-04-11 06:40:12 +0000] SELECT COUNT(*) as _fluent_aggregate FROM `fluent`
[2018-04-11 06:40:12 +0000] CREATE TABLE `fluent` (`id` INTEGER PRIMARY KEY NOT NULL, `name` TEXT NOT NULL, `batch` INTEGER NOT NULL, `created_at` TEXT NOT NULL, `updated_at` TEXT NOT NULL)
[2018-04-11 06:40:12 +0000] SELECT `fluent`.* FROM `fluent` ORDER BY `fluent`.`batch` DESC LIMIT 0, 1
[2018-04-11 06:40:12 +0000] SELECT `fluent`.* FROM `fluent` WHERE `fluent`.`name` = ? LIMIT 0, 1 [Post]
[2018-04-11 06:40:12 +0000] CREATE TABLE `posts` (`id` INTEGER PRIMARY KEY NOT NULL, `content` TEXT NOT NULL)
[2018-04-11 06:40:12 +0000] INSERT INTO `fluent` (`name`, `updated_at`, `id`, `batch`, `created_at`) VALUES (?, ?, ?, ?, ?) [Post, 2018-04-11T06:40:12.762Z, , 1, 2018-04-11T06:40:12.762Z]
[2018-04-11 06:40:12 +0000] SELECT `fluent`.* FROM `fluent` WHERE `fluent`.`name` = ? LIMIT 0, 1 [Users]
[2018-04-11 06:40:12 +0000] CREATE TABLE `userss` (`id` INTEGER PRIMARY KEY NOT NULL, `usename` TEXT NOT NULL, `passWord` INTEGER NOT NULL)
[2018-04-11 06:40:12 +0000] INSERT INTO `fluent` (`name`, `updated_at`, `id`, `batch`, `created_at`) VALUES (?, ?, ?, ?, ?) [Users, 2018-04-11T06:40:12.766Z, , 1, 2018-04-11T06:40:12.766Z]
[2018-04-11 06:40:12 +0000] SELECT `fluent`.* FROM `fluent` WHERE `fluent`.`name` = ? LIMIT 0, 1 [Festival]
[2018-04-11 06:40:12 +0000] CREATE TABLE `festivals` (`id` INTEGER PRIMARY KEY NOT NULL, `date` TEXT NOT NULL, `name` TEXT NOT NULL)
[2018-04-11 06:40:12 +0000] INSERT INTO `fluent` (`name`, `updated_at`, `id`, `batch`, `created_at`) VALUES (?, ?, ?, ?, ?) [Festival, 2018-04-11T06:40:12.770Z, , 1, 2018-04-11T06:40:12.770Z]
Database prepared
No command supplied, defaulting to serve...
Starting server on 0.0.0.0:8080
这是我的模型用户.swift
import MySQLProvider
final class Users: Model {
var usename: String
var passWord: Int
let storage = Storage()
init(row: Row) throws {
usename = try row.get("name")
passWord = try row.get("passWord")
}
init(usename: String, passWord: Int) {
self.usename = usename
self.passWord = passWord
}
func makeRow() throws -> Row {
var row = Row()
try row.set("usename", usename)
try row.set("passWord", passWord)
return row
}
}
extension Users: Preparation {
static func prepare(_ database: Database) throws {
try database.create(self) { user in
user.id()
user.string("usename")
user.int("passWord")
}
}
static func revert(_ database: Database) throws {
try database.delete(self)
}
}
mysql.json文件
{
"hostname": "localhost",
"user": "root",
"password": "123456",
"database": "User"
}
我的配置+设置.swift
extension Config {
public func setup() throws {
// allow fuzzy conversions for these types
// (add your own types here)
Node.fuzzy = [Row.self, JSON.self, Node.self]
try setupProviders()
try setupPreparations()
}
/// Configure providers
private func setupProviders() throws {
try addProvider(FluentProvider.Provider.self)
try addProvider(MySQLProvider.Provider.self)
}
/// Add all models that should have their
/// schemas prepared before the app boots
private func setupPreparations() throws {
preparations.append(Post.self)
preparations.append(Users.self)
preparations.append(Festival.self)
}
}
我不知道问题在哪里,所以我真的希望你能帮我解决这个问题
2条答案
按热度按时间bgibtngc1#
有证据表明,它正在创建一个数据库,但您找不到它,它很可能使用默认的、基于内存的sqlite。看看里面
fluent.json
然后改变主意driver
设置如图所示:您也没有提到driver+config.swift文件,下面是一个示例:
vpfxa7rd2#
你把模型加到准备工作中了吗?