【问题标题】:Laravel Lumen Migrations fail if there are no migrations present如果没有迁移,Laravel Lumen 迁移会失败
【发布时间】:2018-11-10 06:15:59
【问题描述】:

我创建了一个新的 Lumen 项目,目前没有任何迁移。由于我正在设置 CI,因此我希望始终运行 php artisan migrate,以防在某个时候添加迁移。

这是我用于 CI 服务器的 .env 文件:

APP_ENV=testing
APP_DEBUG=true
APP_KEY=base64:ROhueDv4THITTXXfOO14HsMNO/Po5hx1eQndrbt12cA=
APP_URL=http://jarvis-testing.easybell.de

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jarvis_test
DB_USERNAME=dev
DB_PASSWORD=dev

CACHE_DRIVER=file

这是我的database.php 文件:

<?php

return [
    'default'     => 'mysql',
    'connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env( 'DB_HOST' ),
            'port'      => env( 'DB_PORT' ),
            'database'  => env( 'DB_DATABASE' ),
            'username'  => env( 'DB_USERNAME' ),
            'password'  => env( 'DB_PASSWORD' ),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
        ]
    ]
];

当我运行php artisan migrate 时,我收到以下错误:

In Connection.php line 664:

SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8 collate utf8_unicode_ci)


In Connection.php line 452:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''

运行php artisan migrate:status时,输出为:

No migrations found.

所以从我的角度来看,Lumen 在这一点上不应该做任何事情。我在这里错过了什么?

【问题讨论】:

标签: php laravel migration lumen lumen-5.5


【解决方案1】:

在您的迁移文件中,您必须在函数中提及表名。

例子:

$table->foreign('user_id')->references('id')->on('')
    ->onUpdate('cascade')->onDelete('cascade');

上面会显示一个错误,所以我们需要在函数中使用表名

$table->foreign('user_id')->references('id')->on('users')
    ->onUpdate('cascade')->onDelete('cascade');

【讨论】:

  • 不存在迁移文件。
猜你喜欢
  • 2016-02-16
  • 2018-03-08
  • 2019-04-07
  • 1970-01-01
  • 2016-04-06
  • 2014-12-23
  • 2019-12-24
  • 2015-02-05
相关资源
最近更新 更多