SchemaUpdate generating duplicate foreing keys?

96 views
Skip to first unread message

Afshar Mohebbi

unread,
Nov 14, 2010, 8:03:26 AM11/14/10
to nhusers
Hi,

Suppose I have a database that is just created based on some hbms. I
add a field to one of entities and use SchemaUpdate to update databse
with current change. Unfortunately UpdateSchema in addition to
generating ascript to add the new field, gnerates mostly all foregin
key constraints again as duplicate.

Am I missing something or is it a bug?


Regards,
Afshar Mohebbi

Thiago Alves

unread,
Nov 14, 2010, 4:39:55 PM11/14/10
to nhu...@googlegroups.com
It happened to me once. My guess is that you did not specify the foreign key name, so NHibernate generates a random key name. When it does an update, it cannot determine whether the existing key represents the same relationship as the new key, so the relation is created again (please someone correct me if I'm wrong).

I've also heard that Update Schema is not as reliable as dropping the schema and create again. I never use Update because of that

Regards,
Thiago Alves
 


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


Sergey Lobko-Lobanovsky

unread,
Nov 14, 2010, 4:43:12 PM11/14/10
to nhu...@googlegroups.com
I would second this question, and elaborate on it -- is there a way to handle DB schema updates without having to wipe everything and start over with fresh empty new version of the database? 

Afshar Mohebbi

unread,
Nov 15, 2010, 4:01:40 AM11/15/10
to nhusers
Hi Thiago,

I did not specify the foreign key names. So this may be the cause. But
how can do specify that in both NHibernate/Castle ActiveRecord?


Thanks in Advance


On Nov 14, 4:39 pm, Thiago Alves <thiago1...@gmail.com> wrote:
> It happened to me once. My guess is that you did not specify the foreign key
> name, so NHibernate generates a random key name. When it does an update, it
> cannot determine whether the existing key represents the same relationship
> as the new key, so the relation is created again (please someone correct me
> if I'm wrong).
>
> I've also heard that Update Schema is not as reliable as dropping the schema
> and create again. I never use Update because of that
>
> Regards,
> Thiago Alves
>
> On Sun, Nov 14, 2010 at 11:03 AM, Afshar Mohebbi
> <afshar.mohe...@gmail.com>wrote:
>
>
>
> > Hi,
>
> > Suppose I have a database that is just created based on some hbms. I
> > add a field to one of entities and use SchemaUpdate to update databse
> > with current change. Unfortunately UpdateSchema in addition to
> > generating ascript to add the new field, gnerates mostly all foregin
> > key constraints again as duplicate.
>
> > Am I missing something or is it a bug?
>
> > Regards,
> > Afshar Mohebbi
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com­>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.- Hide quoted text -
>
> - Show quoted text -

Afshar Mohebbi

unread,
Nov 16, 2010, 12:30:13 AM11/16/10
to nhusers
Hi,

I found how foreing key names are defined in Castle ActiveRecord. I
must specified ForeignKey property in BelongsTo explicitly.

Thanks you Thiago, you helped me a lot.


Afshar Mohebbi
> > >http://groups.google.com/group/nhusers?hl=en.-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages