2

我正在构建一个虚拟站点来测试 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 文件上正确设置了“前缀”配置。
  • 如果我删除前缀,一切正常。我知道我可以在每次运行的迁移中手动设置前缀,但是...
4

2 回答 2

6

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:resetmigrate这样做了,它的工作很完美

于 2013-04-28T09:20:15.290 回答
1

在 Laravel 5.4.* 上,我最终创建了 artisan 命令以使用以下句柄方法在某些表(不是全局)上添加表前缀。

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();
}

如果有人希望在某些表上添加前缀而不进行全局设置,希望这会有所帮助。

于 2019-04-08T14:23:18.267 回答