The problem is that I have this error:
[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'songs' already exists
This is my migration file:
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateSongsTable extends Migration { public function up() { Schema::create('songs', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id'); $table->string('title'); $table->string('slug')->unique(); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); } }
I think the solution will be just to delete the table then run migration again, so how can I drop a table in Laravel 5 using the command line? I am using MySQL.
First generate an empty migration with any name you'd like. It's important to do it this way since it creates the appropriate date. The only thing I added was drop_table :products and raise ActiveRecord::IrreversibleMigration . Then run rake db:migrate and it'll drop the table for you.
To drop a table, you may use the Schema::drop method:
Schema::drop('users'); // Better Schema::dropIfExists('users');
To drop a table in laravel, Create a first migration
Step to drop a table
$ php artisan make:migration drop_user_table
Add this to your migrate file inside up function Schema::drop('tableName');
public function up() { Schema::dropIfExists(table('songs')); $table->increments('id'); ... }
then run
$ php artisan migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With