因此,似乎SQLite不支持dropping column。在构建应用程序的过程中,我删除/重新添加了列。我将数据库更改为。因此,现在,在我的迁移文件夹中,有一些使用$table->dropColumn('someColumn')
的文件夹。当我使用SQLite
时,该行出现错误(上面的链接中对此进行了解释)。
这告诉我不能使用SQLite。所以我决定使用MySQL:
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'database' => ':memory:',
'prefix' => '',
]
]
];
但我收到一个错误:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
我应该使用什么连接进行单元测试?
最佳答案
MySQL没有像SQLite这样的内存功能,因此'database' => ':memory:'
不起作用(将mysql服务器实例启动到write specifically in memory之前)。只需在app/config/testing/database.php
中设置测试数据库配置:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'test_database',
'username' => '*******',
'password' => '*******',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
并在
setUp
上运行迁移,然后在tearDown
上重置迁移。
关于php - SQLite不支持drop; Laravel单元测试使用什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27348302/