0

I am working on my first Laravel project. I'm trying to create database migrations and run them with artisan migrate. The migrations aren't running and the command returns no output.

Key facts:

  • I used artisan make:migration to create the migration file with the proper filepath.
  • The first time I ran the command, it created the migration table in the database. So I know that it is hitting the database and at least doing something right.
  • When I have no files in the database/migrations folder, I get the Nothing to migrate command.
  • Beyond these two messages, I have received no output at all from the command. No errors, nothing. Furthermore, there are no records in the migration table in the database.
  • artisan migrate --verbose also returns no output.
  • The permissions on storage/logs is drwxrwxrwx. I am the owner of the directory.
  • storage/logs/laravel.log doesn't contain anything pertaining to the migrations.

I've included the code for my first migration below.

This question is different from this question in that the previous user didn't use the proper naming convention. That question contains a detailed answer about the migration process. It's not helpful because I'm not getting any output. I also reviewed the questions suggested by SO as I entered this question.

Perhaps I have something configured incorrectly? What do I need to do to get these migrations running?

2017_01_17_151638_user.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

// Create the classes associated with user management.

class UserMigration extends Migration
{
    public function up()
    {
      Schema::create('tblUser', function (Blueprint $table) {
          $table->increments('id');
          $table->string('name');
          $table->string('email')->unique();
          $table->string('password');
          $table->rememberToken();
          $table->timestamps();
      });

      Schema::create('tblUserPasswordReset', function (Blueprint $table) {
          $table->string('email')->index();
          $table->string('token')->index();
          $table->timestamp('create_date')->nullable();
      });
    }

    public function down()
    {
      Schema::dropIfExists('tblUserPasswordReset');
      Schema::dropIfExists('tblUser');
    }
}
Community
  • 1
  • 1
Jay Bienvenu
  • 3,069
  • 5
  • 33
  • 44
  • Make sure the `/storage/logs` folder is writable; it may be hitting an error and trying to log it there, and depending on your dev environment, it may not be communicating that properly. Beyond that, perhaps include a screenshot of your terminal running the command. – Tim Lewis Jan 17 '17 at 17:02
  • In my case it was XDebug listening and stopping the script. After disabling the listener, the command went through with no errors. – boryn Jun 24 '20 at 08:08

11 Answers11

4

try

php artisan migrate:rollback

then try

php artisan migrate

Laravel keeps track of the migrations ran, so if you have run it before, it knows and wont do it again unless you roll it back and I ran into this until i rolled them back and then ran migrate again

ATechGuy
  • 1,240
  • 8
  • 13
  • No effect. `php artisan migrate:rollback` reports `Nothing to rollback`. `php artisan migrate` afterward does nothing. The migration table is still empty. – Jay Bienvenu Jan 17 '17 at 21:44
  • make:migration create_thetable.php <----- does this command put out anything at all? Also does this: php artisan migrate:reset produce anything? – ATechGuy Jan 17 '17 at 21:52
2

For me the only way to make it work was by restarting the mysql service (in OSX, never saw this on debian).

acubcn
  • 31
  • 2
1

Try:composer dump-autoload

Then run php artisan migrate again

Possible issue: https://stackoverflow.com/a/33974248/7377984

Community
  • 1
  • 1
Paras
  • 9,258
  • 31
  • 55
  • No effect. `composer dump-autoload` reports `Generating autoload files`, but still no action on `php artisan migrate`. – Jay Bienvenu Jan 17 '17 at 21:47
  • Try `php artisan clear-compiled` followed by `composer dump-autoload` then `php artisan optimize` and finally `php artisan migrate` – Paras Jan 17 '17 at 21:48
1

I am pretty sure I just figured out the problem.

I created a new user in MySQL and assigned all rights to all databases through the mysql shell:

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'password';

GRANT ALL ON *.* to 'user1'@'localhost';

Don't forget to change the connection info in .env:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=user1
DB_PASSWORD=password
Tim
  • 11
  • 2
0

Double check the following:

  • Migration files are actually being created in database/migrations
  • Double check the log file and directory is writable
  • Make sure the permissions on the database/migrations folders are the default that come with the laravel install
  • Doublecheck the laravel.log file
Chris
  • 54,599
  • 30
  • 149
  • 186
  • The migration files are in `database/migrations`. The permissions on the `storage/logs` directory are `drwxrwxrwx.` The `laravel.log` file has some older entries but nothing pertaining to migrations. – Jay Bienvenu Jan 17 '17 at 17:14
0
  • First check your Services Apache and Mysql running by going to your localhost/phpmyadmin.
  • check your terminal or cmd that you are in correct filepath directory.
  • then write php artisan migrate
  • if something shows let me know here if not goto your laravel.log for details
Uzair
  • 714
  • 2
  • 6
  • 17
0

Do not miss to add your migrations to DatabaseSeeder.php. Refer to this documentation Calling Additional Seeders.

Within the DatabaseSeeder add this:

$this->call(UserMigration::class);

Hope it helps.

0

Had this exact problem with none of the listed solutions changing anything. The unmentioned solution that works in this case for me was

composer update --no-scripts

I had wiped out everything and was starting from scratch, forgot to re init composer and install everything.

0

The only way I have been able to reproduce a case where Migrations run without error yet do not migrate is by having not specified a database schema name in the config along with a connection name.

In either in the .env file ensure that the following settings has a value:

DB_CONNECTION=master
DB_DATABASE=my_databse_name

or alternatively in /config/database.php :

'default' => env('DB_CONNECTION', 'master'),

'connections' => [

        'master' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'my_databse_name'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => 'cms_',
            'strict' => true,
            'engine' => null,
        ],
],
Marc
  • 5,109
  • 2
  • 32
  • 41
0

i had this issue earlier this month what i did was i checked the confiuration to mysql server carefully the restart the mysql server and the IDE itself

abokor hassan
  • 356
  • 6
  • 17
0

I think the class name of the migration should be User and not UserMigration as laravel looks for the class using file name and your file have a slug user not user migration.