2

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 table data_types drop controller)

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?

Wayne Smallman
  • 1,690
  • 11
  • 34
  • 56
  • @pawel7318, I read that a while ago and it doesn't help; as I said, I don't know what key it's referring to. – Wayne Smallman Nov 30 '17 at 09:42
  • **Please note:** While this question has been asked, the answers provided here and in the other answer are inapplicable in this instance. I had to use Docker to solve this problem. – Wayne Smallman Dec 01 '17 at 11:31

0 Answers0