Closed benjdum59 closed 7 years ago
It seems that I read The config file but Database (through provider) is not initialized when I use it in Entity class
Have you actually created the database with name vapor
in your mysql server? And the user vapor
with password vapor
? I had the same setup and it worked for me.
Yes: ~/Documents/Development/ mysql -u vapor -pvapor mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.7.16 Homebrew
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | vapor | +--------------------+ 2 rows in set (0.00 sec)
mysql> use vapor Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed mysql>
Which Vapor and MySQL provider version are you using? I've just tried with the exact same setup as you have and it seems to work for me.
This is my Package manager configuration file:
import PackageDescription
let package = Package(
name: "HelloWorld",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 1),
.Package(url: "https://github.com/vapor/mysql-provider.git", majorVersion: 1, minor: 0),
.Package(url: "https://github.com/vapor/fluent.git", majorVersion: 1, minor: 1)
],
exclude: [
"Config",
"Database",
"Localization",
"Public",
"Resources",
"Tests",
]
)
I've just created a project with the same setup and everything works as expected. Could you possibly share your project?
Of course. Thanks for helping: https://github.com/benjdum59/vapor-tuto
So, I've done these steps:
vapor xcode --mysql
in the root of the repo in terminalAnd everything worked fine and as expected.
I think that it looks like something is wrong with your MySQL setup. Could you try using an app like Sequel or something similar and connect to the the database that's running locally and see if that succeeds? Maybe if you could also do a clean clone of the repo and same steps as I did, just to see if it still doesn't work that might help.
I'm still having the issue. Using sequel, I connected to the database with the configuration used inside project.
Closing this for now due to inactivity. Feel free to re-open if it's unsolved.
Using the secrets/mysql.json file, I've got the error "Uncaught Error: EntityError.noDatabase. Use middleware to catch this error and provide a better response. Otherwise, a 500 error page will be returned in the production environment."
This is my configuration file:
My MySQL server is running. This is the code I use in Main.swift:
And my entity file: