Laravel 5.6 migrations

Clash Royale CLAN TAG#URR8PPP
Laravel 5.6 migrations
I have a problem with migrations in a Laravel 5.6.
This is a problem:

My code in a Laravel:
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateCompaniesTable extends Migration
/**
* Run the migrations.
*
* @return void
*/
public function up()
Schema::create('companies', function (Blueprint $table)
$table->increments('id');
$table->string('name');
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
);
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
Schema::dropIfExists('companies');
What i need to do?
Try with
Schema::hasTable('tableName')– Nouphal.M
Aug 8 at 13:11
Schema::hasTable('tableName')
I am sorry. I thought 5.6 :D.
– Boban Mladenovic
Aug 8 at 13:12
It is complaining that the table already exists. If you are trying to run this migration it may be worth dropping the existing table currently. If you want to run all migrations again (Warning will loose all data) you can run
php artisan migrate:fresh– Kyle Wardle
Aug 8 at 13:13
php artisan migrate:fresh
can you post a screenshot of your migrations folder
– Salman Zafar
Aug 8 at 13:26
2 Answers
2
Table already exists as it is telling you in the message, you may need to drop it first or check that you're using the right database name in your ENV file. Also check you're not creating the table companies in a previous migration.
If you're trying to add fields to an existing table you don't need the create method but:
Schema::table("companies", function (Blueprint $table)
// The fields you need
);
Also for the foreign key is safer to use unsignedInteger as data type
As shown in the error message "companies" table already exist.
you can use following commands to resolve it.
php artisan migrate:rollback
php artisan migrate:reset
please refer the laravel documentation for more details.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Laravel 6.6 does not exist. Did you mean Laravel 5.6?
– Kyle Wardle
Aug 8 at 13:11