I'm trying to learn Laravel Eloquent. It's my first migration and it produces error. I'll try to describe it by pasting the relevant output of the things I've done:
The goal: To create new table 'author_metadatas'.
The question: How to do it?
At first, I remove manually everything in the database as if I'm starting from scratch. Please note that I found solution for the problem, so author_metadatas exists, but I'm quite convinced my solution cannot be correct and it will break something later. Also note that I set 2017 in the date of my migration to 2016 out of desperation when I was trying to make it work. Turned out it didn't help.
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 51
Server version: 10.1.22-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use library;
Database changed
MariaDB [library]> show tables;
+-------------------+
| Tables_in_library |
+-------------------+
| author_metadatas |
| migrations |
| users |
+-------------------+
3 rows in set (0.00 sec)
MariaDB [library]> drop table author_metadatas;
Query OK, 0 rows affected (0.10 sec)
MariaDB [library]> select * from migrations;
+----+-------------------------------------------------+-------+
| id | migration | batch |
+----+-------------------------------------------------+-------+
| 1 | 2016_06_10_051345_create_author_metadatas_table | 1 |
+----+-------------------------------------------------+-------+
1 row in set (0.00 sec)
MariaDB [library]> drop table migrations;
Query OK, 0 rows affected (0.09 sec)
MariaDB [library]> drop table users;
Query OK, 0 rows affected (0.09 sec)
MariaDB [library]> show tables;
Empty set (0.00 sec)
MariaDB [library]> quit
Let's check our migration files. We have three of them. The first two with dates from 2014 are the ones that seem to create the problem. They came with Laravel.
+++++@----- c:\xampp\htdocs\library
# cd database\migrations
+++++@----- c:\xampp\htdocs\library\database\migrations
# dir
Volume in drive C has no label.
Volume Serial Number is 722D-1AD2
Directory of c:\xampp\htdocs\library\database\migrations
06/10/2017 09:38 AM .
06/10/2017 09:38 AM ..
06/10/2017 09:38 AM 781 2014_1012000000_create_users_table.php
06/10/2017 09:38 AM 715 2014_10_12_100000create_password_resets_table.php
06/10/2017 09:38 AM 887 201706_10_051345_create_author_metadatas_table.php
3 File(s) 2,383 bytes
2 Dir(s) 15,130,337,280 bytes free
Start migration. The PDO Exception seems to stop the process of applying migrations in the middle.
+++++@----- c:\xampp\htdocs\library\database\migrations
# cd ....
+++++@----- c:\xampp\htdocs\library
# 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 (SQL: 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
Check MySQL database
+++++@----- c:\xampp\htdocs\library
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 53
Server version: 10.1.22-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use library;
Database changed
MariaDB [library]> show tables;
+-------------------+
| Tables_in_library |
+-------------------+
| migrations |
| users |
+-------------------+
2 rows in set (0.00 sec)
MariaDB [library]> select * from migrations;
Empty set (0.00 sec)
MariaDB [library]> quit
So 'the solution'. Delete the migrations that came with Laravel.
+++++@----- c:\xampp\htdocs\library
# php artisan migrate
Migrating: 2017_06_10_051345_create_author_metadatas_table
Migrated: 2017_06_10_051345_create_author_metadatas_table
+++++@----- c:\xampp\htdocs\library
# php artisan migrate
Nothing to migrate.
+++++@----- c:\xampp\htdocs\library
Thanks for the help in advance!