Skip to content
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

ModelBuilder: API for removing indexes and foreign keys #7605

Open
Tracked by #22952
rowanmiller opened this issue Feb 13, 2017 · 9 comments
Open
Tracked by #22952

ModelBuilder: API for removing indexes and foreign keys #7605

rowanmiller opened this issue Feb 13, 2017 · 9 comments

Comments

@rowanmiller
Copy link
Contributor

Split off from #7530

Currently there is no way to remove an index that was introduced by convention. You have to use internal APIs to do it.

@rowanmiller rowanmiller added this to the Backlog milestone Feb 13, 2017
@divega
Copy link
Contributor

divega commented Feb 17, 2017

Possibly a generalization of #2725 could help this scenario, i.e. an annotation that once added to an element in metadata, instructs migrations not to create the corresponding database object for it.

@collinbarrett
Copy link

collinbarrett commented Feb 7, 2018

Ran into a requirement for this and finally stumbled upon this Issue. The workaround suggested by @AndriySvyryd here doesn't seem to work for me. Internal APIs may have changed.

Let me know if I can assist at all with this feature.

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Feb 7, 2018

@collinbarrett The current workaround is to disable conventions by calling

((Model)modelBuilder.Model).ConventionDispatcher.StartBatch();

But since this is also Internal code and will be broken in the future

@collinbarrett
Copy link

Ah, ok, thanks, @AndriySvyryd . Hmm, yeah, I probably don't want to disable conventions globally at this point. Will probably just manually remove from migrations for now. Thanks!

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Feb 7, 2018

The conventions will only be disabled after that call is made, so if the only thing that follows is removing indexes then nothing else would be affected, see #10855 (comment)

@ajcvickers
Copy link
Member

Note: see workarounds on #6239.

@Shane32
Copy link

Shane32 commented May 26, 2022

I'm having the same issue; I need a table without an index on a foreign key, and the above solutions are not officially supported, and the workaround listed in #6239 does not work. At the moment, I am manually modifying the migration to prevent the index from being created.

@schuettecarsten
Copy link

I have created an implementation of IModelFinalizingConvention and use this to remove all indexes from the model when the model builder finalizes it. This is a bit tricky, but works like a charm.

@rofenix2
Copy link

still no solution to this day?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants