gpt4 book ai didi

php - Laravel PHP Artisan迁移:refresh giving a syntax error

转载 作者:行者123 更新时间:2023-12-03 08:06:35 24 4
gpt4 key购买 nike

这是代码:

public function up()
{
Schema::create('articles', function (Blueprint $table) {

$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at');

$table->foreign('user_id')->refrences('id')->on('users')->onDelete('cascade');
});

错误:

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1 near ")": syntax error (SQL: create table "articles" ("id" integer not null primary key autoincrement, "user_id" int eger not null, "title" varchar not null, "body" text not null, "created_at"
datetime not null, "updated_at" datetime not null, "published_at" datetime not null, foreign key("user_id") references "users"() on delete cascade))

[PDOException] SQLSTATE[HY000]: General error: 1 near ")": syntax error



有任何想法吗?

最佳答案

您可以使用引用代替引用

public function up()
{
Schema::create('articles', function (Blueprint $table) {

$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at');

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
来解决错字错误

关于php - Laravel PHP Artisan迁移:refresh giving a syntax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34417635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com