简体   繁体   中英

Laravel 5.3 migration doesn't create tables

I created some migrations using the command php artisan migrate:make and then filled it and saved it with some fields. This is a fresh installation and the first migration to run.

I ran php artisan migrate and the migration completed successfully. However, while the migrations table IS created, and it has a single row with the filename and batch 1, there is no table.

Here's my migration file code:

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

And a few lines from my 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),
    ],

I did try changing the host to 127.0.0.1 but that wouldn't connect. How can I fix it so that it does create the table like it's supposed to.

The problem is with the following lines:

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

You should be getting an exception similar to the following

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1427 For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'latitude').

when you do the migration.

Change to the following

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

and it should work.

Numeric precision refers to the maximum number of digits that are present in the number

如果没有出现任何错误,请尝试运行composer dumpauto来注册迁移,然后运行php artisan migrate来运行迁移。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM