首页 > 解决方案 > Laravel API Authentication api 向用户迁移表失败

问题描述

步骤 1. php artisan make:migration add_api_token_to_users_table --table=users。

步骤 2. 将其插入模式表 api_token_to_users_table。

Schema::table('users', function ($table) {
$table->string('api_token', 80)->after('password')
                    ->unique()
                    ->nullable()
                    ->default(null);
});

步骤 3. 使用 php artisan migrate 运行 migrate。

当我运行 php artisan migrate 时,出现此错误。

PDOException::("SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以获取在 'after 附近使用的正确语法password) 默认字符集 utf8mb4在第 1 行整理“utf8mb4_unicode_ci”)

Laravel 版本 5.8.38

标签: mysqllaravel

解决方案


当您使用 nullable() 方法时,该字段将默认设置为 NULL。


推荐阅读