I'm creating a development version of a Laravel 5.4 application, which is working, albeit without a complete database.
When I ran php artisan migrate
it generated most of the tables, but some failed, though without errors.
When I then attempted an import via phpMyAdmin, I got an error:
#1071 - Specified key was too long; max key length is 767 bytes
... on a number of tables, which happen to be the ones the migration failed to create (it's worth noting that some of the tables have multiple keys, so the error itself is — to me at least — a bit vague).
As an example:
CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(10) unsigned DEFAULT NULL,
`order` int(11) NOT NULL DEFAULT '1',
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`slug` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `categories_slug_unique` (`slug`),
KEY `categories_parent_id_foreign` (`parent_id`),
CONSTRAINT `categories_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Here, the name
and slug
columns are satisfying the length criteria, but still triggering errors.
public function up()
{
// Create table for storing categories
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable()->default(null);
$table->foreign('parent_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('set null');
$table->integer('order')->default(1);
$table->string('name');
$table->string('slug')->unique();
$table->timestamps();
});
}
Both the categories
and data_types
tables have an "up" function in them, but Laravel is ignoring them when I run php artisan migrate
or triggering an error when I run php artisan migrate:refresh
:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.data_types' doesn't exist (SQL: alter tabledata_types
dropcontroller
)
The production application uses MySQL 5.7 while the development application uses 5.6, which I understand is the cause.
Anyone know how I get around this, without using Docker?