0

I'm trying to move an existing code base to using EF6 migrations for its context against a Postgres database

After creating an initial migration, and trying to apply it to an empty database, I get errors that the contraint names already exist. It seems to be related to the truncation done by EF6 (or migrations) to handle the constraint name limit of Postgres

Is there any way to override this behavior, instead of truncation, trucate and add a hash of the full name to keep the uniqeness?

Or is there any other way to solve the issue? I guess oracle dbs have the same issue? Anyone solved it in relation to them?

Erik Karlsson
  • 570
  • 1
  • 6
  • 17

1 Answers1

1

It is not EF issue. By default indentifiers in PostgreSQL are limited to 63 bytes:

The system uses no more than NAMEDATALEN-1 bytes of an identifier; longer names can be written in commands, but they will be truncated. By default, NAMEDATALEN is 64 so the maximum identifier length is 63 bytes. If this limit is problematic, it can be raised by changing the NAMEDATALEN constant in src/include/pg_config_manual.h.

So you should look there first. Some info here also

In one of my previous projects where we have used PostrgeSQL I've ended with just assigning needed names manually. Also you can look into custom conventions (or this answer) if you are using code first, but I have not used them personally.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Thanks, the a link in the answer you linked seems to be the way to go, even having an example of a ForeginKey convention: https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/conventions/model?redirectedfrom=MSDN – Erik Karlsson Jul 23 '20 at 13:51