【发布时间】:2022-01-11 17:35:04
【问题描述】:
我有一个名为clients 的表,如下所示:
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->id();
$table->string('user_name')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('phone_number')->unique();
$table->string('email_address')->nullable()->unique();
$table->string('password')->nullable();
$table->enum('registration_process', [0, 1, 2, 3, 4, 5]);
$table->rememberToken();
$table->timestamps();
});
}
我想插入这样的数据:
public function stepOne(Request $request)
{
$validData = $request->validate([
'phone' => ['required','unique:clients,phone_number']
]);
$client = Client::create([
'phone_number' => "0".$validData['phone'],
'registration_process' => 0
]);
return redirect(route('client.login'));
}
如您所见,我已将 registration_process' 设置为 0,但问题是它返回此错误:
SQLSTATE[01000]:警告:第 1 行的“registration_process”列的 1265 数据被截断
正如this 问题的答案所说,我尝试在mysql.connections 中将strict 设置为database.php 的false,然后又尝试了一次,这一次,错误消失了,但数据没有被插入,它以某种方式设置为 empty:
那么这里出了什么问题?我该如何解决这个问题?
更新:
127.0.0.1/digipayesh/clients/ http://localhost/phpmyadmin/tbl_sql.php?db=digipayesh&table=clients
Your SQL query has been executed successfully.
show create table `clients`
clients CREATE TABLE `clients` (
`id` bigint(20) unsigne...
【问题讨论】:
-
在您的数据库上设置查询日志并查看正在传递的内容。检查表的创建方式并确保它具有适当的值。
ENUM列通常不被视为字符串吗? -
考虑到 miken32 所说的,
'registration_process' => '0'有效吗? -
您能否将
show create table语句的完整输出发布为文本? -
@ÁlvaroGonzález 是的,但我不知道该怎么做,请你帮帮我,我真的被这个困住了......
-
模型的
$fillable数组中是否有registration_process?