我是 Laravel 的新手,我正在尝试使用Schema
外观创建表格。我使用命令创建迁移文件
php artisan make:migration create_products_define_standards_table --create=products_define_standards
这是文件:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStandardsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products_define_standards', function (Blueprint $table) {
$table->increments('id');
$table->string('code')->unique();
$table->string('image');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products_define_standards');
}
}
它确实具有与 default 几乎相同的内容CreateUsersTable
,但是当我运行php artisan migrate
它时,它会创建:
users
' 表(默认)migrations
' 表(默认)
但不是:
password_resets
' 表(默认)products_define_standards
' 表(自定义)
我试过了,php artisan migrate:fresh
但我得到了相同的日志:
Dropped all tables successfully.
Migration table created successfully.
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
at /home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664
660: // If an exception occurs when attempting to run a query, we'll format the error
661: // message to include the bindings with SQL, which will make this exception a
662: // lot more helpful to the developer instead of just the database's errors.
663: catch (Exception $e) {
664: throw new QueryException(
665: $query, $this->prepareBindings($bindings), $e
666: );
667: }
668:
669: return $result;
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
/home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 458
2 PDOStatement::execute()
/home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 458
我找到了这个答案,我也跑composer dumpauto
了,但结果是一样的。
我错过了什么吗?我应该做任何其他事情来在其他地方注册迁移吗?