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
{
    /**
     * Run the migrations.
     *
     * @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);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @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 但无法连接。我该如何修复它,以便它确实像它应该的那样创建表。

4

1 回答 1

2

问题在于以下几行:

$table->decimal('latitude', 3, 7);
$table->decimal('longitude', 3, 7);

您应该会收到类似于以下内容的异常

[PDOException] SQLSTATE[42000]:语法错误或访问冲突:1427 对于 float(M,D)、double(M,D) 或 decimal(M,D),M 必须 >= D(“纬度”列)。

当您进行迁移时。

更改为以下

$table->decimal('latitude', 10, 7);
$table->decimal('longitude', 10, 7);

它应该可以工作。

数值精度是指数字中存在的最大位数

于 2016-12-22T19:43:28.443 回答