How to create this table? #1071 - Specified key was too long; max key length is 1000 bytes
This common problem mostly occurs because by default MySql uses character limit for column names. Which is:
INNODB utf8mb4 VARCHAR(191)
What we need is given below:
INNODB utf8 VARCHAR(255)
To get rid of this issue, I would suggest to use utf8 while creating database along with COLLATE set to utf8_general_ci. I prefer to use below command to create database in MariaDb or MySql:
DROP DATABASE IF EXISTS <YOUR_DATABASE_NAME>;
CREATE DATABASE <YOUR_DATABAE_NAME> DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Above command helped me in my specific scenario. I use 'Sequelize' to create tables on run time. When I tried to run my code in Ubuntu after creating database with simple 'CREATE DATABASE ' command, I got this 1071 error.
Running above command with utf8 character set and collate helped me get rid of the error.
PRIMARY KEY (realurl,catagory)
has a size of (200 + 200) * 3 = 1,200 bytes, which is greater than the 1,000 byte limit, as MySQL stores utf8 encoded chars as 3 bytes.
You'll need to reduce the size of the the fields that make up the primary key or you can upgrade MySQL version to the latest release.
Also see this other question: Error: Specified key was too long; max key length is 1000 bytes.
I solved this issue. Create your database using the following command .
CREATE DATABASE <DB_NAME> CHARACTER SET utf8;