Laravel 5.3 迁移不会创建表格
Laravel 5.3 迁移不会创建表格
我使用命令php artisan migrate:make创建了一些迁移,并填充了一些字段后保存。这是一次全新安装和首次运行的迁移。
我运行了php artisan migrate命令,迁移成功完成。然而,尽管迁移表已经创建,且有一行记录包含文件名和批次1,但没有表格。
以下是我的迁移文件代码:
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateFuelLocationsTable extends Migration { /** * 运行迁移。 * * @return void */ public function up() { // Schema::create('fuel_locations', function (Blueprint $table) { $table->increments('id'); $table->string('uid'); $table->string('name'); $table->string('fuel_type'); $table->string('email'); $table->string('street'); $table->string('city'); $table->string('state'); $table->string('zip'); $table->string('phone'); $table->string('service_hours'); $table->string('payment_methods'); $table->string('payment_method_other'); $table->decimal('latitude', 3, 7); $table->decimal('longitude', 3, 7); }); } /** * 撤销迁移。 * * @return void */ public function down() { // Schema::dropIfExists('fuel_locations'); } }
还有一些来自我的config/database.php的代码:
'mysql' => [ 'driver' => 'mysql', 'database' => 'mydb', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'charset' => env('DB_CHARSET', 'utf8'), 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), 'prefix' => env('DB_PREFIX', ''), 'timezone' => env('DB_TIMEZONE', '+00:00'), 'strict' => env('DB_STRICT_MODE', false), ],
我尝试将主机更改为127.0.0.1,但无法连接。我该如何修复这个问题,使其像应该创建表格一样?
问题出现的原因是在创建表时,使用了错误的 decimal 数据类型的参数。在 Laravel 5.3 中,如果使用了错误的参数,将会抛出异常。异常信息显示 M 必须大于等于 D。
解决方法是将参数修改为正确的值。
具体来说,将原来的代码:
$table->decimal('latitude', 3, 7); $table->decimal('longitude', 3, 7);
修改为:
$table->decimal('latitude', 10, 7); $table->decimal('longitude', 10, 7);
这样修改后,再进行迁移操作,问题将会得到解决。
参考资料:[Stack Overflow](https://stackoverflow.com/questions/2377174#answer-2377176)