Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bastolakancha's avatar

Problem migrating table after creating students table

C:\xampp\htdocs\crud>php artisan make:migration create_students_table
Created Migration: 2017_05_12_111547_create_students_table

C:\xampp\htdocs\crud>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` tim
  estamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)



  [PDOException]
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
0 likes
6 replies
bipin's avatar

delete all table as well as migrate table from you database its occour due to migration table in your database

bastolakancha's avatar

I have created a students table with following attributes but the problem is it doesnot migrate to mysql. What is the problem? <?php

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

    class CreateStudentsTable extends Migration
    {
    /**
     * Run the migrations.
         *
     * @return void
     */
        public function up()
        {
            Schema::create('students', function (Blueprint $table) {
                $table->increments('std_id');
                $table->string('std_name');
                $table->string('std_email')->unique();
                $table->string('std_password');
                $table->rememberToken();
                $table->timestamps();
                });
        }

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

I deleted migrations table and users table and again migrated it. The following error occured and users and migrations table migrated but not students table.

C:\xampp\htdocs\crud>php artisan migrate
Migration table created successfully.


  [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key 
was too long; max key length is 767 bytes (SQ
  L: alter table `users` add unique `users_email_unique`(`email`))



  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key 
was too long; max key length is 767 bytes
bipin's avatar

what syntax you have in user table? i think you modify your users table

 class CreateUsersTable extends Migration

{

   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();
      });
   }

     public function down()
       {
        Schema::dropIfExists('users');
       }
  }

and migrate again hope this will help

bipin's avatar
bipin
Best Answer
Level 2

for student write like this

       public function up()
    {
        Schema::create('students', function (Blueprint $table) {
            $table->increments('id');   or 
             $table->string('std_id');   
            $table->string('std_name');
            $table->string('std_email')->unique();
            $table->string('std_password');
            $table->rememberToken();
            $table->timestamps();
            });
    }

    public function down()
    {
          Schema::dropIfExists('students');
    }
 }

Please or to participate in this conversation.