2
votes

I am trying to create a model (MySQLStringModel) and set an id(of String ? type) to it. There is no errors or any other message in console, and save(on: req) works successfully , but model doesn't appear in Table of the database. Whats can be wrong?

func create(_ req: Request, person: Person) throws -> Future<Person> {
    return Person(id: person.id, name: person.name).save(on: req)
}

P.s.: All works when I use MySQLModel with Int? id, and I don't set this id directly (it sets automatic with autoincreament )

1

1 Answers

5
votes

The problem in method .save(on: req)

As said in the documentation: 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.

So, method .create(on: req) helped me, and new raw appeared in the table.