Laravel 5.3迁移不会创建表 [英] Laravel 5.3 migration doesn't create tables
问题描述
我使用命令php artisan migrate:make创建了一些迁移,然后将其填充并保存了一些字段.这是全新安装,并且是首次运行的迁移.
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.
我运行了php artisan迁移,迁移成功完成.但是,虽然创建了迁移表 IS ,并且该表只有一行包含文件名和批处理1,但是没有表.
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');
}
}
还有我的config/database.php中的几行内容:
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),
],
我确实尝试将主机更改为127.0.0.1,但无法连接.我该如何修复它,以使其确实按预期方式创建表.
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.
推荐答案
问题在于以下几行:
$table->decimal('latitude', 3, 7);
$table->decimal('longitude', 3, 7);
您应该会遇到类似于以下内容的异常
You should be getting an exception similar to the following
[PDOException] SQLSTATE [42000]:语法错误或访问冲突:1427 对于float(M,D),double(M,D)或小数点(M,D),M必须> = D(列 纬度").
[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').
进行迁移时.
更改为以下
$table->decimal('latitude', 10, 7);
$table->decimal('longitude', 10, 7);
它应该可以工作.
这篇关于Laravel 5.3迁移不会创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!