New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specified Key was too long with IdentityContext and InnoDB #136
Comments
From MySQL documentation below: The utf8 character set in MySQL has these characteristics:
Therefore, 80 chars will end up being 240 bytes. Do you have a composite key in one of your tables that might exceed that 767 byte limit? |
There are some composite keys. the biggest one has 3 columns, but even with that it should be fine with 80 characters. 80 * 3 * 3 = 720. This does not seem to be the issue. |
Found the issue. The 767 byte limit also applies to indexes and there were some with VARCHAR(256). Guess they use the term "key" loosely. Thanks for the help. If anyone stumbled upon this with similar issue, this is what my fluent API looks like now:
|
This is also covered in functional test DbContext here: |
@caleblloyd Could you set 127 as the key field default maxlength. |
I hope this doesn't open this back up, but I thought I would add a note as well - please close if it opens it back up. It seems that if I use MariaDB (10.1.22 || 5.5.54) with unicode collations (ex. utf8_unicode_ci, utf8_general_ci), I have to use similar methods from @stephen-cernota and @Mats391, namely I need this in my dbcontext OnModelCreating() override to avoid the max key length exceptions:
However, using MySQL (5.7.17), I do NOT have to do anything at all (I do not need a custom OnModelCreating() override in my DbContext)- just the project defaults, and I do not get any of the key length errors when using IdentityDbContext I just thought that was worth mentioning, as there seems to be a difference between MariaDB and MySQL in this test at least. |
I got the error too. I generate the sql and find the next statements cause the error. My database character set is uft8('utf8', 'utf8_general_ci', 'UTF-8 Unicode', '3' CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE UNIQUE INDEX CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX CREATE UNIQUE INDEX INSERT INTO |
@Cassaba Please re-read this thread, you will find that your answer is to override OnModelCreating. |
This got reported before, but caleblloyd asked me to make new issue.
Original: #81
When using the IdentityContext for asp.net Identity, I get the error "Specified key was too long; max key length is 767 bytes"
Stack trace:
I already tried all the suggetions from the original issue. I set all keys to have a max length that should be small enough and made sure that the DB uses utf8_unicode_ci. I even tried way lower values then the ones below.
Gist of Migration:
https://gist.github.com/Mats391/51a3b9f9103f4c3902dfa1bec5f1d678
The weird part is that it creates everything fine. Only the migration does not get added into the
__efmigrationshistory
. I suspect the error get thrown when it tries to write into the history. The history has PK MigrationId VARCHAR(95). I can use the DbContext fine, only applying new migrations forces me to recreate everything from scratch.I found out that it only happens when I set it to use InnoDB, If I keep it as MyISAM everything works fine.
Versions
"Microsoft.EntityFrameworkCore": "1.1.0-preview1-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0-preview1-final",
"Pomelo.EntityFrameworkCore.MySql": "1.1.0-preview1-*"
The text was updated successfully, but these errors were encountered: