1
votes

This is the code:

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');
        });

And the error:

[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

Any ideas?

1
where is closing brace for up function } at the end of functionSurace
Instead of $table->foreign('user_id')->refrences('id')->on('users')->onDelete('cascade'); you should add $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - Check typo in "references"Kamal Joshi
Hi, welcome to Stack Overflow! It's often beneficial when troubleshooting these types of errors to give a little more context to your question itself. What were you trying to accomplish? How did you go about it? What was the result? How have you tried to troubleshoot? What do you need from the community? You've covered a couple of these, but you're more likely to attract well-thought-out answers if you can provide some more details and whole sentences.ConnorCMcKee
@Kamal I think he copied the text but accidentally removed the e in the question, because in the error you can see it is correctly spelled.davejal
Thanks guys, the problem was in the 'references' word, i probably should kill myself for staying over an hour on this, but ugh probably won't, thanks again for you @Kamal, and the others ofc.Omar Tarek

1 Answers

2
votes

Here is the typo error you can use references instead of refrences

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');
        });