foreign-keys

Hibernate Issue : Foreign key must have same number of columns as referenced primary key

 ̄綄美尐妖づ 提交于 2019-11-27 14:13:34
Goal : I want to have importJobId in ImportJob as foreign key for id of allocation table, such that when we have importJobId then and then only we can have id in allocation as without Job there cannot be any allocations. ImportJob table has composite primary key as [ORGID,IMPORTJOBTYPE] and am trying to get create foreign key relationship in hibernate using <id name="id" column="ID"> <generator class="native"/> </id> <many-to-one name="importjobid" class="com.delta.pdo.admin.ImportJob" cascade="save-update"/> in Allocation.hbm.xml which is not working out and am getting error message as:

MySQL errorno 121

為{幸葍}努か 提交于 2019-11-27 13:52:57
I'm getting this error in MySQL create. I'm doing: CREATE TABLE `blogReply` ( `Id` INT(24) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key of This Table', `blogId` INT(24) NOT NULL COMMENT 'Blog where this reply was posted', `userId` INT(24) NULL COMMENT 'User the blog was posted by', `name` VARCHAR(100) NULL DEFAULT 'Unknown' COMMENT 'The Name of the user that the reply was posted by', `email` VARCHAR(100) NULL DEFAULT 'Unknown' COMMENT 'The Email of the user that the reply was posted by', `http` VARCHAR(300) NULL DEFAULT 'Unknown' COMMENT 'The Webaddress of the user that the reply was posted by

How do I rename a foreign key in mysql?

若如初见. 提交于 2019-11-27 13:30:37
问题 We've just completed a long-running migration on a large table, and ended up with the following constraint on our conversation_tags table: CONSTRAINT `conversation_tags_ibfk_1` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) Unfortunately, there was a bug somewhere, because what we wanted was: CONSTRAINT `fk_conversation_tags_tags` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) Dropping and re-adding the constraint would mean another two long queries. Is there any way to rename the

Is there a severe performance hit for using Foreign Keys in SQL Server?

两盒软妹~` 提交于 2019-11-27 13:27:10
I'm trying my best to persuade my boss into letting us use foreign keys in our databases - so far without luck. He claims it costs a significant amount of performance, and says we'll just have jobs to cleanup the invalid references now and then. Obviously this doesn't work in practice, and the database is flooded with invalid references. Does anyone know of a comparison, benchmark or similar which proves there's no significant performance hit to using foreign keys? (Which I hope will convince him) There is a tiny performance hit on inserts, updates and deletes because the FK has to be checked.

MySQL “ERROR 1005 (HY000): Can't create table 'foo.#sql-12c_4' (errno: 150)”

非 Y 不嫁゛ 提交于 2019-11-27 13:25:33
I was working on creating some tables in database foo , but every time I end up with errno 150 regarding the foreign key. Firstly, here's my code for creating tables: CREATE TABLE Clients ( client_id CHAR(10) NOT NULL , client_name CHAR(50) NOT NULL , provisional_license_num CHAR(50) NOT NULL , client_address CHAR(50) NULL , client_city CHAR(50) NULL , client_county CHAR(50) NULL , client_zip CHAR(10) NULL , client_phone INT NULL , client_email CHAR(255) NULL , client_dob DATETIME NULL , test_attempts INT NULL ); CREATE TABLE Applications ( application_id CHAR(10) NOT NULL , office_id INT NOT

What exactly is a foreign key?

佐手、 提交于 2019-11-27 13:19:37
问题 Ok. So I know what a primary key in DB is. If you have a table in a database, a primary key is a single value that is unique to each row in your table. For example: id | name | whatever ------------------------- 1 Alice .... 2 Bob .... 45 Eve .... 988 .... .... So I need a good, simple example to explain what exactly a foreign key is. Because I just don't get it :) Edit: OK it's pretty easy, I guess I was over-complicating the problem. So one final question, the only restriction on foreign

MS SQL “ON DELETE CASCADE” multiple foreign keys pointing to the same table?

白昼怎懂夜的黑 提交于 2019-11-27 12:46:09
Howdy, I have a problem where i need a cascade on multiple foreign keys pointing to the same table.. [Insights] | ID | Title | | 1 | Monty Python | | 2 | Spamalot | [BroaderInsights_Insights] | broaderinsight_id | insight_id | | 1 | 2 | Basically when either record one or two in the insights table is deleted i need the relationship to also be deleted.. I've tried this: CREATE TABLE broader_insights_insights(id INT NOT NULL IDENTITY(1,1), broader_insight_id INT NOT NULL REFERENCES insights(id) ON DELETE CASCADE, insight_id INT NOT NULL REFERENCES insights(id) ON DELETE CASCADE, PRIMARY KEY(id))

Enabling Foreign key constraints in SQLite

巧了我就是萌 提交于 2019-11-27 12:38:26
I'm using SQLite with C# and have some tables with foreign keys defined. Now, I know that by default foreign key constraints are not enforced in SQLite, but I'd like to turn them ON. Is it possible to do this through code? I have looked up a related question , but I'm not sure how to do it through C# code. I'm using the latest plug-in of SQLite available for Visual Studio 2008 for designing my tables. conn.Open(); SQLiteCommand cmd = new SQLiteCommand("PRAGMA foreign_keys = ON", conn); cmd.ExecuteNonQuery(); conn.Close(); I need this change to persist when this connection is reopened. Is it

set initial value in CreateView from ForeignKey (non-self.request.user)

若如初见. 提交于 2019-11-27 12:20:19
问题 I am attempting to access ForeignKeys in Class Based Views CreateView. I would like to be able to dynamically set initial values in CBV from ForeignKeys and also dynamically set template links from ForeignKeys. These two questions (1. initial values, 2. template links) may be solved in similar methods, or perhaps by different methods... I'm still learning. Perhaps the first question can be solved within views.py and the second question can be solved with template syntax in ingredient_form

How do I add a Foreign Key Field to a ModelForm in Django?

耗尽温柔 提交于 2019-11-27 12:07:38
What I would like to do is to display a single form that lets the user: Enter a document title (from Document model) Select one of their user_defined_code choices from a drop down list (populated by the UserDefinedCode model) Type in a unique_code (stored in the Code model) I'm not sure how to go about displaying the fields for the foreign key relationships in a form. I know in a view you can use document.code_set (for example) to access the related objects for the current document object, but I'm not sure how to apply this to a ModelForm. My model: class UserDefinedCode(models.Model): name =