2

Tying to create a new table in laravel schema and command php artisan make:migration create_asks_table --create tasks and having the schema like

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('body');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

        Schema::dropIfExists('tasks');
    }
} ?>

and I am trying to create table using php artisan migrate command but it is not considering new table tasks to create it tries to create first table user that is already existing table that has been created in default and the error is

>php artisan migrate

[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table users (id int unsigned not null auto_increment primary key, name varchar(255) not null, email varchar(255) not null, password varchar(255) not null, remember_token varchar(100) null, created_at timestamp null, updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

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

How can should I skip already existing table to create:

enter image description here

1

1 Answer 1

0

Did you already create a users table before running migrations for the first time? Laravel comes with a migration that creates the users and passwords table in the format that Laravel expects.

That error means that the database you are migrating against already has the table users, but you have a migration file to create the users table in the migrations folder.

I reproduced the issue so I can help you understand it and walk through it with me:

  1. I ran php artisan migrate and get this error:

    [Illuminate\Database\QueryException]                                                                    
    SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' 
    already exists (SQL: create table `us...  
    
  2. I checked my database and confirmed the users table exists.

  3. I ran this query to check the migrations already created by laravel:

    select * from migrations;
    
  4. I confirmed that the users migration is in my database and it's file is named this: the Users migration in my database
    Looking at my Migrations folder I see that the file name is different (could be because I imported an old laravel schema for example): enter image description here

In this case, all I have to do is rename the users file to this migration name.

nfml-5YF:admin$ php artisan migrate
Nothing to migrate.

If you created your own custom Users table and don't want laravels precanned users table If you created your own users table, then remove the users migration from the migrations folder. I typically create a pre-migrated folder in my migrations folder and drag the migrations I don't want in there.

I will warn you though that if you created your own users table, but still want to use Laravel's authentication workflow.... that you have to make sure it has all the fields laravel requires with the same field names, like a placeholder for the encrypted password, the login timestamps it requires, and the password hash to confirm passwords and usernames.

Sign up to request clarification or add additional context in comments.

7 Comments

Ok ,but i am trying to create table name task not user help on that
Did you look in your migrations folder as I recommended? I'm confident you will see the users migration file I mentioned, which isn't registered in the migrations table. That is the only reason you would receive this error. You have a migration that wasn't migrated file for a table that exists.
Ok,my database schema structure is like in this link Screen shot of database scheme structure. If so then how to add that user table to migration table.
Laravel's migration class will migrate every file in the migrations folder that isn't in the migrations table sequentially. As mentioned in my response, you have two options. 1. Remove the users migration file that comes with Laravel from the migrations folder. 2. If you migrated a users table as part of an old Laravel install then find that old name in the migrations table and rename your file to that name.
Actually, i am new to laravel and i have started learning from starting i would like to use default user table to authenticate , i have created that user table from default command php artisan migrate and i found that schema while i downloaded laravel from composer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.