Reputation: 744
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?
Upvotes: 1
Views: 770
Reputation: 259
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');
});
Upvotes: 2