Laravel mysql migrate error

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Troubleshooting Laravel MySQL Migrate Errors on MacOS with SQL Mode Issues Body: Recently, you encountered an issue while migrating your database information from Github to your local setup. After cloning the project, installing MySql and Sequel Pro, you received a strange error related to SQL mode. This blog post aims to provide you with a comprehensive understanding of this issue and offer solutions to help you resolve it. The problem can be attributed to improper MySQL configuration settings. To better analyze and fix the situation, let's break down the information you provided: Versions: 1. Mysql 8.0.11 2. Laravel 5.6.12 3. PHP 7.1.14 (cli) DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=fisica DB_USERNAME=xxx DB_PASSWORD=xxx To understand the error, you first need to know what SQL mode is and how it affects your database setup: SQL Modes in MySQL SQL modes are used to control various aspects of statement interpretation. They can have a significant impact on query results. You might encounter different modes like STRICT_TRANS_TABLES, NO_ENGINE_SUBSTITUTION, and others depending on the version of MySQL you're using. One of these is NO_AUTO_CREATE_USER - a mode that prevents the creation of accounts in the 'root' database by default. Now that we understand SQL modes let's address your specific error: Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER' This error is generated because Laravel's migrations system uses the MySQL CLI which has a default behavior of setting sql_mode=NO_AUTO_CREATE_USER. Unfortunately, this conflicts with your current MySQL version that might have different SQL mode settings or none set at all. To solve this issue, you can: 1. Change SQL modes in MySQL configuration files 2. Disable the Laravel migrations' default sql_mode setting 3. Ensure that your environment has correct MySQL packages installed Solution 1: Modifying SQL Modes in MySQL Configuration Files If there is no specific reason to use the NO_AUTO_CREATE_USER mode, you can modify your MySQL configuration file (my.cnf) to reflect this change. By default, this file is located in /etc/mysql/ on Linux-based systems and C:\Program Files\MySQL\MySQL Server 8.0\my.ini on Windows OS. Add the following lines to your config file: [mysqld] sql_mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES" Save and restart MySQL to implement these changes. Alternatively, you can use command line options like -D --default-authentication-group=root for MySQL 8.0 or -T --skip-grant-tables for older versions. Consult the official MySQL documentation for more information on SQL modes. Solution 2: Disabling Laravel's Default SQL Mode Setting To disable Laravel's default sql_mode setting, you can set it to null in your .env file, which should be located in your project folder. Open the file and add this line: DB_SQLSTATEMIGRATIONS=null This should allow your migrations to proceed without issues. Be aware that this solution might cause compatibility problems with other applications or libraries requiring strict SQL modes. You can switch it back after completing your migration process. Solution 3: Ensure Correct MySQL Packages are Installed If you're using a package manager like Homebrew or the Microsoft Web Platform Installer, make sure that you have installed the correct versions of PHP and MySQL for Laravel. The Laravel documentation also offers guidance on setting up proper environments, including MySQL configuration. Conclusion: In summary, understanding SQL modes is critical to solving your Laravel database migration issues. By following the solutions provided in this post or exploring alternative approaches, you should be able to successfully migrate your database and resolve any connected errors that might arise. Always ensure compatibility across all tools involved and consult the relevant documentation for more information on configuring MySQL settings when needed. Remember to always back up your database before making significant changes or modifications to your configuration files. Happy coding!