Deleting foreign keys

2,152 views
Skip to first unread message

qntmfred

unread,
Jun 14, 2011, 9:22:55 PM6/14/11
to FluentMigrator Google Group
What is the correct syntax for deleting foreign keys? Thanks

Jeff Treuting

unread,
Jun 14, 2011, 9:30:39 PM6/14/11
to fluentmigrato...@googlegroups.com
Depends on how you created it.

If you have an existing FK where you know the name then you can do this:

Delete.ForeignKey("FK_Name").OnTable("TableA");

However if you create the FK in a migration by doing:

Create.ForeignKey()
                .FromTable("TableA").ForeignColumn("ColumnA")
                .ToTable("TableB").PrimaryColumn("ColumnB");

Then you can delete it by doing:

Delete.ForeignKey()
                .FromTable("TableA").ForeignColumn("ColumnA")
                .ToTable("TableB").PrimaryColumn("ColumnB");




On Tue, Jun 14, 2011 at 6:22 PM, qntmfred <kjwa...@gmail.com> wrote:
What is the correct syntax for deleting foreign keys? Thanks

--
You received this message because you are subscribed to the Google Groups "FluentMigrator Google Group" group.
To post to this group, send email to fluentmigrato...@googlegroups.com.
To unsubscribe from this group, send email to fluentmigrator-goog...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluentmigrator-google-group?hl=en.




--
Jeff Treuting
Truburn Solutions, LLC
(206) 393-0717
www.truburn.net
je...@truburn.net



qntmfred

unread,
Jun 14, 2011, 11:07:06 PM6/14/11
to FluentMigrator Google Group
I don't seem to have a .PrimaryColumn() method off .ToTable()

I had been trying this

Delete.ForeignKey()
.FromTable("TableA").ForeignColumn("ColumnA")
.ToTable("TableB");

and it threw an exception.

I have been using the named relationship syntax as you suggested, but
I didn't necessarily want to bother naming them.

I am using the latest version on nuget - is this a bug?


On Jun 14, 9:30 pm, Jeff Treuting <j...@truburn.net> wrote:
> Depends on how you created it.
>
> If you have an existing FK where you know the name then you can do this:
>
> Delete.ForeignKey("FK_Name").OnTable("TableA");
>
> However if you create the FK in a migration by doing:
>
> Create.ForeignKey()
>                 .FromTable("TableA").ForeignColumn("ColumnA")
>                 .ToTable("TableB").PrimaryColumn("ColumnB");
>
> Then you can delete it by doing:
>
> Delete.ForeignKey()
>                 .FromTable("TableA").ForeignColumn("ColumnA")
>                 .ToTable("TableB").PrimaryColumn("ColumnB");
>
> On Tue, Jun 14, 2011 at 6:22 PM, qntmfred <kjwar...@gmail.com> wrote:
> > What is the correct syntax for deleting foreign keys? Thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "FluentMigrator Google Group" group.
> > To post to this group, send email to
> > fluentmigrato...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > fluentmigrator-goog...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/fluentmigrator-google-group?hl=en.
>
> --
> *Jeff Treuting*
> Truburn Solutions, LLC
> (206) 393-0717www.truburn.net
> j...@truburn.net

Jeff Treuting

unread,
Jun 14, 2011, 11:26:14 PM6/14/11
to fluentmigrato...@googlegroups.com
The Nuget package is 0.9 and old.  There has been some talk in this group about getting it more up to date, so I'm thinking that will happen relatively soon.

This bug was fixed a while ago and if you get the latest bits from github then it will work as expected.

If you need to use the Nuget package then you can get around it by specifying the FK name and using that syntax instead as it works on that version.

Josh Coffman

unread,
Jun 17, 2011, 2:04:06 AM6/17/11
to fluentmigrato...@googlegroups.com
I was going to update the nuget package but seems I'd need to either create a new package or get the original person to update it. (Sean?)

-j

Sean Chambers

unread,
Jun 17, 2011, 7:41:34 AM6/17/11
to Josh Coffman, fluentmigrato...@googlegroups.com
I wasn't the one who originally created it. Why cam only a certain person update it?

Sent from my Windows Phone

From: Josh Coffman
Sent: Friday, June 17, 2011 2:04 AM
To: fluentmigrato...@googlegroups.com
Subject: Re: Deleting foreign keys

Thomas G. Mayfield

unread,
Jun 17, 2011, 9:57:45 AM6/17/11
to FluentMigrator Google Group
I think it unlikely that Sean misspelled his own name. You'll want to
hit the "Report Abuse" link on http://nuget.org/List/Packages/FluentMigrator
and get the current package removed (or just try uploading a new
version and see if it forbids it--there are no owners registered for
the project).

Josh Coffman

unread,
Jun 17, 2011, 10:34:14 AM6/17/11
to fluentmigrato...@googlegroups.com
I'll see if I can do it later today. May need to remind me.

@rebootd



Chris Marisic

unread,
Aug 12, 2011, 12:35:29 PM8/12/11
to fluentmigrato...@googlegroups.com
I just had issues trying to figure this out today.

I commented on https://github.com/schambers/fluentmigrator/issues/118#issuecomment-1792548

I feel FM should be able to tell you if you didn't have OnTable, instead of just blowing up with a NRE.
Reply all
Reply to author
Forward
0 new messages