3

I've installed Laravel 5 and Valet (v2.0.12) using Homebrew on my Macbook Pro (running High Sierra (10.13.6)). I've downloaded a clean Laravel project (laravel new blog).

When I try to migrate (sitting in the project folder, then using php artisan migrate), nothing happens. Terminal just sits there doing nothing. Command is being executed, but then nothing. No error, no success, nothing. Even adding -v gives nothing.

I am able to get into the server through command line. I've entered the right credentials inside the .env file. I can even run other php artisan commands, but all of the migrate commands don't do anything.

My migration files are:

2018_09_04_100609_create_users_table.php

<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

2018_09_04_100659_create_password-resets_table.php

<?php

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

class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('password_resets');
    }
}

Update:

Checked DB connection using the following:

try {
    DB::connection();
    die("success!");
} catch (\Exception $e) {
    die("Could not connect to the database.  Please check your configuration. error:" . $e );
}

I got "success!".

But then I change DB::connection() to DB::connection()->getPdo() it does nothing again. Or isn't that relevant?

dnwjn
  • 171
  • 13
  • Care to share your migration file? Without it, we can only guess. – sskoko Sep 04 '18 at 10:06
  • Have you made tables in migration folder? – Zain Farooq Sep 04 '18 at 10:06
  • I've added the code to my original post. – dnwjn Sep 04 '18 at 10:17
  • Try php artisan migrate --force – sskoko Sep 04 '18 at 10:25
  • or php artisan migrate:refresh – sskoko Sep 04 '18 at 10:29
  • Can you do a `php artisan migrate:status` to see if there are any migrations pending? – brombeer Sep 04 '18 at 10:30
  • None of the `php migrate` functions work... – dnwjn Sep 04 '18 at 10:33
  • Are you sure your app can correctly connect to your database from .env values ? – Mtxz Sep 04 '18 at 10:45
  • If you manually create a model Table in your database, are you able to insert values using Eloquent or Laravel SQL queries ? – Mtxz Sep 04 '18 at 10:49
  • 1
    @Mtxz https://stackoverflow.com/questions/33432752/laravel-5-1-checking-a-database-connection check this question, and also can you share you env file (db section) – Teoman Tıngır Sep 04 '18 at 10:50
  • @Mtxz check out the update I posted. – dnwjn Sep 04 '18 at 10:51
  • @HasanTıngır nice tip! thanks! – Mtxz Sep 04 '18 at 10:51
  • @BlackFayah could you try a `composer dump-autoload` and `migrate` again. (edit: thanks for updating your question). Maybe [this](https://stackoverflow.com/questions/22291704/one-of-my-migrations-is-not-running-with-the-php-artisan-command-in-laravel-4) can help. – Mtxz Sep 04 '18 at 10:53
  • @HasanTıngır actually just tried out the method from the question you linked! – dnwjn Sep 04 '18 at 10:54
  • @Mtxz still same result... – dnwjn Sep 04 '18 at 10:55
  • does it throw error with `DB::connection()->getPdo()` ? – Teoman Tıngır Sep 04 '18 at 10:56
  • @BlackFayah, well it's strange... I would try to delete all migrations (back them up), create a new migration from `php artisan make:migration create_users_table`, then `composer dumpautoload` then `migrate` again. – Mtxz Sep 04 '18 at 10:56
  • I think before this issue, you deleted tables (except migration table). And when you try to migrate again, laravel checked out migration table and saw migrations already done and it couldn't find other migration ? – Teoman Tıngır Sep 04 '18 at 10:59
  • @HasanTıngır Nope. Just created the database, then tried to migrate. Haven't done anything else. Edit: `DB::connection()->getPdo()` doesn't throw anything. – dnwjn Sep 04 '18 at 11:36
  • @Mtxz Still nothing... – dnwjn Sep 04 '18 at 11:37
  • Really? Even after creating a new migration from scratch? Can you try add the `--path` argument and specify your migration paths? [see](https://laracasts.com/discuss/channels/general-discussion/l5-php-artisan-migrate-path-option?page=1) – Mtxz Sep 04 '18 at 11:50
  • @Mtxz still not doing anything. Edit: even tried it with Laravel 5.5 this time. – dnwjn Sep 04 '18 at 11:58
  • Wao.. So you clone an entirely new laravel, add a simple migration, and it does not work at all? I'm out of ideas ^^` – Mtxz Sep 05 '18 at 09:14

2 Answers2

2

I got it fixed. I would add a lot of exclamation marks after that, but I don't feel like it. Why?

Because the problem was that I was using MySQL, whilst I should've been using MariaDB. The guide didn't mention that anywhere, so I just assumed that MySQL was enough. Apparently not. Would've been nice if the error showed something like that...

dnwjn
  • 171
  • 13
  • How did you get it fixed? – Raccoon Feb 10 '20 at 08:00
  • @Raccoon if I recall correctly I switched from MySQL to MariaDB, but unfortunately I can't remember the specifics on that. – dnwjn Jun 15 '20 at 20:00
  • Someone who reaches here. This command fails after several minutes, For me, it was 4 mins. So, first and foremost, check your database connection. The project I cloned from GH, changed `DB_CONNECTION` to `DB_DEFAULT`. For that reason it was not picking the right connection and the command I was running didn't work. – ssi-anik Mar 05 '23 at 02:46
0

I was facing a similar issue where none of the migrate options or migrate itself worked and I was getting no errors the command just seemed to hang. I switched from MySQL to MariaDB after coming across this page and after a lot of other tries. This finally worked.

This is how I did it. Following this article:- How To Install MariaDB on Ubuntu 20.04 (I was installing it to a droplet on digitalocean but I believe the concept will be helpful for anyone.

Install MariaDB:

sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation

Open MariaDB and create admin user:

sudo mariadb
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

Test to ensure DB is running as needed:

sudo systemctl status mariadb

if not running:

sudo systemctl start mariadb

For a complete explanation, visit the link I shared

Also, if you have MySQL already installed, you will have to remove it otherwise it will result in MariaDB failing when you reboot. I faced this issue later and MariaDB kept hanging when I tried starting it and I got a MYSQL 2002 error on the browser. Here's how -

sudo systemctl stop mariadb
echo "/usr/sbin/mysqld { }" | sudo tee /etc/apparmor.d/usr.sbin.mysqld
sudo apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld

Running these commands should display

Removal succeeded for "/usr/sbin/mysqld".

Then, run this

sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld

Lastly, restart mariadb

sudo systemctl start mariadb

All should be working well now and will be preserved even after a reboot.

Doreen Chemweno
  • 303
  • 2
  • 6