我在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时,我的DB中只有默认的laravel用户(和迁移)表。没有货币一号。
可能是什么原因?
编辑
所有的迁移都很好。问题是:
照明\数据库\QueryException SQLSTATE42000:语法错误或访问冲突: 1071指定的键太长;最大键长度为767字节(SQL: alter用户添加唯一的users_email_unique(电子邮件)) PDOException SQLSTATE42000:语法错误或访问冲突: 1071指定的键太长;最大键长度为767字节
解决方案是在AppServiceProvider.php中添加这个
public function boot()
{
Schema::defaultStringLength(191);
}发布于 2018-02-08 10:10:56
您需要运行composer du来首先注册迁移类。
然后运行php artisan migrate命令来执行新的迁移。
发布于 2018-02-08 10:18:56
打开AppServiceProvider.php,编写以下代码:
public function boot()
{
Schema::defaultStringLength(191);
}表名必须是复数回滚您的迁移使用
php artisan migrate:rollback或
从数据库和迁移表中手动删除表,并尝试以下代码:
migration command:
php artisan make:migration create_currencies_table代码:
class CreateCurrenciesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('currencies', 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('currencies');
}
}现在快跑
php artisan migrate发布于 2018-02-08 10:27:03
所有迁移记录都记录在表migrations.It中,这表明您创建了表before.So,删除了表迁移中有关货币的记录,然后再次运行php artisan migrate。更重要的是,刷新数据库并检查表货币是否已创建。
https://stackoverflow.com/questions/48682828
复制相似问题