【发布时间】:2018-07-18 20:47:11
【问题描述】:
我在文件2018_02_08_094356_create_currency_table.php..的迁移中添加了一个新表。
这是代码:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCurrencyTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('currency', function (Blueprint $table) {
$table->increments('id');
$table->decimal('usdeur', 15, 2);
$table->decimal('usdchf', 15, 2);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('currency');
}
}
当我运行php artisan migrate 时,我的数据库中只有默认的 laravel 用户(和迁移)表。没有货币。
可能是什么原因?
编辑
迁移一切正常。问题是这样的:
[Illuminate\Database\QueryException] SQLSTATE[42000]:语法错误或访问冲突:1071 指定的键太长;最大密钥长度 为 767 字节(SQL:alter table users add unique users_email_unique(email))
[PDOException] SQLSTATE[42000]:语法错误或访问冲突:1071 指定的密钥太长;最大密钥长度为 767 字节
解决方案是在AppServiceProvider.php中添加这个
public function boot()
{
Schema::defaultStringLength(191);
}
【问题讨论】:
-
如果您没有需要保留的数据,请先运行
php artisan migrate:fresh。听起来您在数据库中有迁移记录。这将删除您的所有表格,因此请注意。