【发布时间】:2013-10-04 20:42:53
【问题描述】:
尝试在开发环境中使用 sqlite。它似乎可以正确检测环境,但是当我尝试迁移到 development.sqlite 时出现异常“数据库不存在”
工匠命令
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
据我所知,如果文件不存在,laravel 应该创建文件,但由于它不存在,我尝试手动创建文件,但仍然抛出异常。
更新:环境可能有问题,因为如果我为数据库尝试 ':memory' 也会发生同样的事情。
更新 2:我尝试运行示例单元测试,但添加到 TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* @return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
尽管测试环境已经随 laravel 一起提供,但这也给出了相同的异常。所以我会看看我是否能找到任何新的问题。
【问题讨论】: