Add the table to the on method $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')
Having trouble running php artisan migrate:refresh
When ever I try to run php artisan migrate:refresh I get one of two errors
if my tables haven't been removed manually I get:
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'articles' already exists (SQL: create table articles (id int unsigned not null auto_increment primary key, user_id int unsigned not null, title varchar(255) not null, body text not nu
ll, created_at timestamp null, updated_at timestamp null, published_at timestamp not null) default character set utf8 collate utf8_unicode_ci)
and
[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'articles' already exists
I think this has something to do with my migrations down method
public function down()
{
Schema::drop('articles');
}
Next if I go into my database and just manually delete the tables before running the refresh command I get this:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table articles add constraint articles_user_id_foreign foreign key (user_id) references `` (id) on delete cascade)
where my create method looks something like this
public function up()
{
Schema::create('articles', function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at');
$table->foreign('user_id')
->references("id")
->onDelete('cascade');
});
}
any help/guidance is appreciated
Please or to participate in this conversation.