我正在构建一个虚拟站点来测试Laravel 3.x。
我现在正在创建我的网站迁移。在出现以下错误之前,一切正常:
SQLSTATE[42s02]: Base table or view not found: 1146 Table 'databasenamehere.prefix_laravel_migrations' doesn't exist
问题是laravel突然开始给'laravel_migrations'表加上前缀(当它应该只对其他表这样做时)。
我想知道我是否做错了什么,或者这是一个已知的问题。
我正在尝试运行以下迁移(使用php artisan migrate application命令):
public function up()
{
Schema::create('siteinfo', function ($table)
{
$table->engine = 'InnoDB';
$table->string('name');
$table->string('title')->nullable();
$table->string('corp_name')->nullable();
$table->string('corp_addr')->nullable();
$table->string('corp_phone')->nullable();
$table->string('corp_city')->nullable();
$table->string('corp_state')->nullable();
$table->string('corp_email')->nullable();
$table->string('main_url')->nullable();
$table->timestamps();
});
}
请帮忙就太好了。
编辑1:
- 我注意到几分钟前,我的表没有前缀,即使"前缀"配置正确设置在config/database.php文件。
- 一切工作正常,如果我删除前缀。我知道我可以在每次迁移中手动设置前缀,但是……
在application->config->database.php
中设置prefix
如下
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'foodb',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => 'ula_', <-- this is where you need to set the table prefix
),
设置完成后,migrate:reset
和migrate
再次设置我这样做过,效果很好
在Laravel 5.4。*,我最终创建了artisan命令,使用下面的handle方法在某些表(不是全局)上添加表前缀。
public function handle()
{
$this->tablePrefix = 'tmp_';
// Set table prefix
DB::setTablePrefix($this->tablePrefix);
$data = [
'--path' => [
'database/prefixed-migrations' // Directory Path to migrations which require table prefix
],
'--database' => 'cli',
'--force' => true
];
$this->call('migrate', $data); // Next call the migration
Model::reguard();
}
希望这有助于如果有人希望在某些表上前缀而不全局设置它。