简体   繁体   中英

php artisan migrate is not doing anything

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?

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM