我正在研究 Laravel 并在 php artisan 中工作,但我不断收到此错误:
用消息'SQLSTATE [23000]照亮/数据库/查询异常:完整性约束违规:19 NOT NULL约束失败:profiles.url(SQL:插入“profiles”(“title”,“description”,“user_id”,“updated_at” , "created_at") 值 (Cool, Desc, 1, 2020-03-12 02:03:16, 2020-03-12 02:03:16))'
我正在将配置文件附加到用户,并且我的用户表包含以下内容:
>> User::all()
=> Illuminate\Database\Eloquent\Collection {#2992
all: [
App\User {#2993
id: "1",
name: "Test User1",
email: "test1@test.com",
username: "test1",
email_verified_at: null,
created_at: "2020-03-12 02:01:08",
updated_at: "2020-03-12 02:01:08",
},
], }
这是我在 PHP Artisan 中输入的
>>> $profile = new \App\Profile();
=> App\Profile {#2987}
>>> $profile->title = 'Cool Title';
=> "Cool Title"
>>> $profile->description = 'Desc';
=> "Desc"
>>> $profile->user_id = 1;
=> 1
>>> $profile->save();
Profiles_table.php
class CreateProfilesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->bigIncrements('id')->nullable;
$table->unsignedBigInteger('user_id')->nullable;
$table->string('title')->nullable;
$table->text('description')->nullable;
$table->string('url')->nullable;
$table->timestamps();
$table->index('user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('profiles');
}
}
我找不到失败的原因。希望有人能找出是什么原因造成的。谢谢
慕的地10843