php - 迁移期间 Laravel 未知数据库错误
问题描述
我无法在 Homestead/Vagrant 框中运行 Laravel 迁移。这样的问题还有很多,但似乎没有一个适合我的答案。
我建立了一个博客网站,它在 VirtualBox 中的路径是/home/vagrant/code/blog
. /home/vagrant/code/blog/database/database.sqlite
然后我按照文档中的说明创建了一个代表 SQLite 数据库的空文件。此外,我编辑了/home/vagrant/code/blog/.env
文件以包含“正确”的数据库信息:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=/home/vagrant/code/blog/database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret
然后我使用这里php artisan make:migration create_users_table
解释的方法创建了一个迁移。但是,当我尝试使用此迁移时,出现以下错误:php artisan migrate,
vagrant@homestead:~/code/blog$ php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database '/home/vagrant/code/blog/database/database.sqlite' (SQL: select * from information_schema.tables where table_schema = /home/vagrant/code/blog/database/database.sqlite and table_name = migrations and table_type = 'BASE TABLE')
at /home/vagrant/code/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [1049] Unknown database '/home/vagrant/code/blog/database/database.sqlite'")
/home/vagrant/code/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=/home/vagrant/code/blog/database/database.sqlite", "homestead", "secret", [])
/home/vagrant/code/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
所以它说即使我输入了它的绝对路径它也找不到数据库,这怎么可能?我知道路径必须正确,因为当我运行ls /home/vagrant/code/blog/database/database.sqlite
它时它被列为现有文件..
我怎样才能解决这个问题?
解决方案
改变这个:
DB_CONNECTION=mysql
有了这个:
DB_CONNECTION=SQLite
在你的 .env 文件中
推荐阅读
- python - 在给定日期范围内持有的最大股票数量
- flutter - 容器颤动中的调用方法
- nearprotocol - 如何从其地址调用不同的合约?
- ruby - Puppet RSpec 测试的正确目录结构
- sorting - Jinja2中的版本号排序列表
- c# - 使用 IMongoQueryable 进行单元测试。System.InvalidCastException:无法将 EnumerableQuery 类型的对象转换为 IOrderedMongoQueryable 类型
- r - 如何在 R 中使用 lat 和 long 遍历列并计算距离
- mysql - 如何从星期几和星期中获取上一年
- c# - EF Core 和 Asp.Net Core 中多租户的动态连接字符串
- python - 我正在尝试使用 scipy.signal.welch(x, fs=1.0, window='hann', nperseg=None, noverlap=None) 计算 PSD