I have four migrations file and when I run php artisan migrate
in the command line it says:
Nothing to migrate
I also tried with php artisan migrate --database=vcp
:
Database [vcp] not configured.
I used another database in my .env
file and ran php artisan migrate
command again:
Migration table created successfully.
Nothing to migrate.
running
php artisan migrate:refresh
, php artisan migrate:reset
, php artisan migrate:status
, php artisan migrate --path="database/migrations/migration_file"
whit these messages
Nothing to rollback.
Nothing to migrate.
No migrations found
and
composer dump-autoload or composer update
didn't help.
here is my .env
file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vcp
DB_USERNAME=root
DB_PASSWORD=secret
my 2017_05_10_201750_add_columns_to_users.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddColumnsToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('status')->default('online');
$table->string('api_token');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('status');
$table->dropColumn('api_token');
});
}
}
please help!
Here's what worked for me:
First, delete all your database tables including the migrations table. Second, the update method up() of your AddColumnsToUsers file like this:
public function up()
{
DB::beginTransaction();
try {
Schema::table('users', function (Blueprint $table) {
$table->string('status')->default('online');
$table->string('api_token');
});
DB::commit();
} catch (PDOException $e) {
DB::rollBack();
$this->down();
}
}
This checks your database to see if table already exists, it creates the table if it doesn't exist and rollbacks if it does. Let me know if this worked.