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

had's avatar
Level 1

Migration Problem

Hi everyone! Beginner level question here:

I'm learning Laravel. I'm falling in love with it. And then, I just can't seem to get migration to work and I'm totally stuck.

I have three migrations total, under migrations folder. Only one new that I created called blog. The other two are users and password_resets, which I think came with the Laravel install. When I go to look at my tables after I ran my first migration trial (with errors) I see that users is created. There's also a table called migrations. However, I can't get the other two tables to appear.

Btw, I saw something online that I should add this line to database.php and did that. 'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock', It didn't make a difference it looks like. (also the first table seemed to have migrated before I made this change so probably unnecessary to add this)

ERRORS:

When I go and try to run php artisan migrate I get this error (also tried php artisan migrate:refresh). Error is long, and in two parts, in red boxes.

First one: [illuminate/database/queryexception], SQLState[42501]: Base table or view already exists: 1050 users already exists. (Sql create table users 'id' int unassigned not null auto increment primary key, 'name' varcar 255.... etc...

Second red box: [PDO Exception] , [SQLstate[42501]; Base table or view already exiss. 1050 users already exists.

Thank you for any help everyone!

Had

0 likes
6 replies
vipin93's avatar

delete manually all table from database included migration table and rerun php artisan migrate

goatshark's avatar

@had What happens if you php artisan migrate:reset? That should roll back any migrations you've already performed and put you in a spot to re-run php artisan migrate. Both of those steps can be accomplished at the same time with a php artisan migrate:refresh, but I would do them one at a time to see what happens.

Alternatively, assuming you're just starting and aren't going to lose any data that you care about, I would drop the database and recreate it. After that, try php artisan migrate.

Sometimes my migrations get out of sync with the 'migrations' table in the database (only by user error, for the record). Check out that table, btw. It'll give you good insight into how migrations are really tracked.

had's avatar
Level 1

I deleted the tables manually and reran. This is the error I get when I first run php artisan migrate. And back to same position as my first post..

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

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes

had's avatar
Level 1

Tried totally deleting the whole database and redoing the steps and still no go.

By the way here's the schema from migration file:

Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps();

had's avatar
Level 1

Thank you Snapey! That was it indeed! And thanks everyone for trying to help.

Please or to participate in this conversation.