Closed Rubenfer closed 4 years ago
In Fluent 4, you need to run the migrations separately from running the server:
vapor run migrate
I believe there is a flag that you can set for auto-migrating, but I don't remember what that is.
Thanks @calebkleveter. Working and the flag to auto migrate is --auto-migrate.
I experienced the same "error: no such table:" situation. From what Rubenfer sais, "vapor run migrate" seems to have solved his issue.
Not my case, though.
What happened: "vapor run migrate" created my db.sqlite file inside my project's folder (neighboring Package.swift). When the application started, it searched for it in /Users/myUserName/Library/Developer/Xcode/DerivedData/MyProjectName-followed_by_some_long_mumbo_jumbo_string/Build/Products/Debug.
Simply moving the db.sqlite file inside the DerivedData_based contraption solved my problem (as a test --- I feel it should live (and be searched for) in a better chosen location...)
@florinadrianodagiu You need set the working directory of your project to Package.swift folder. You can change it on schema settings > Run > Options.
I call app.autoMigrate()
app.databases.use(DatabaseConfigurationFactory.sqlite(.file("db.sqlite")), as: .sqlite)
app.migrations.add(CreateFlowStorage())
app.autoMigrate()
I've tried to setup a simple Vapor 4 project and when I configure it the migrations doesn't run.
Steps to reproduce
Expected behavior
When the project builds and run, if you try to access http://localhost:8080/todos it returns an empty array of todos.
Expected JSON response: []
Actual behavior
http://localhost:8080/todos returns
[ ERROR ] error: no such table: todos
When the server starts no info messages about migrations, so looks like the migrations are not running.Actual JSON response:
Environment
Configuration file contains: