PHP artisan migrate not creating new table

Prabin Parajuli picture Prabin Parajuli · Apr 8, 2016 · Viewed 29.9k times · Source

I am new to Laravel and I'm following Laravel Documentations as well as few Tutorial Videos. However, I am running this php artisan migrate code in my local CMD prompt and it's not creating Database Table in phpmyadmin. There are other few similar topics related to this in stackoverflow but none solved my issue. Please don't mark this duplicate.

Ok, it goes like this. I run this code

php artisan make:migration create_student_table --create=student

and new file is created in migration folder as 2016_04_08_061507_create_student_table.php

Then in that file I run this code

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

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

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

Then in cmd I run php artisan migrate but it didn't create student table. Instead it's showing this message

[PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

I created users table few days ago using similar method as above. But new student table is not being created. Am I missing anything here? Thanks in advance.

Answer

Jeff picture Jeff · Apr 8, 2016

That means Laravel is trying to run the users table migration first. If you are in development and don't need to keep your data, you can just delete the users table and then run php artisan migrate