0
голосов
2ответов
683 просмотров

Problem with related entity on asp.net MVC create form using entity framework

I am building a very simple asp.net MVC file upload form. Currently I have a problem creating the new database object that stores info on said file. The code for the action method looks as follows: [Authorize(Roles = "Admin")] public ActionResult AddFile(Guid? id) { var org = or...

5
голосов
8ответов
3201 просмотров

How to enforce DB integrity with non-unique foreign keys?

I want to have a database table that keeps data with revision history (like pages on Wikipedia). I thought that a good idea would be to have two columns that identify the row: (name, version). So a sample table would look like this: TABLE PERSONS: id: int, name: varchar(30), ...

0
голосов
1ответов
155 просмотров

How do I clear a table with a lot of references in oracle?

For instance, suppose I have table A. Then I have tables B-Z that have a foreign key to table A's primary key. Then perhaps there are also some tables that have a foreign key constraint to a table in B-Z's primary key constraint. Is there any easy way to clear out table A and all of the tables...

1
голосов
1ответов
593 просмотров

MYSQL Create table + Alter table incorrect syntax?

I'm trying to create a table in Navicat and immediately add a foreign key relation after that. The syntax however seems to be incorrect... Is this even possible? CREATE TABLE `Bld` ( `id` int(10) NOT NULL PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TA...

5
голосов
5ответов
1812 просмотров

How to seek foreign key violations on whole database? (I'm currently using MySQL)

In databases where foreign key checking has been disabled in the past, how can one check for foreign key constraint violations?

2
голосов
1ответов
747 просмотров

List foreign keys linking to a model

How can I display objects that link to an object via a ForeignKey in Django (specifically in the admin interface). For example, if I click on an object, I'll not only see the object but also any other object that link to it. e.g. I have a model for "Manufacturer" and another one for "Model"...t...

14
голосов
5ответов
10212 просмотров

How to use MySQL index columns?

When do you use each MySQL index type? PRIMARY - Primary key columns? UNIQUE - Foreign keys? INDEX - ?? For really large tables, do indexed columns improve performance?

1
голосов
1ответов
972 просмотров

Generic Foreign Keys and get_or_create in django 1.0: Broken?

As you can see, create() works, but get_or_create() doesn't. Am I missing something obvious here? In [7]: f = FeedItem.objects.create(source=u, dest=q, type="greata") In [8]: f, created = FeedItem.objects.get_or_create(source=u, dest=q, type="greata") -------------------------------------------...

0
голосов
2ответов
191 просмотров

MySQL: Use 2 keys, one to join, one to sort?

I have a simple where clause on a keyed field, a join between two tables on a different field, and then a sort on another field of the second table. I have keys on everything, but it seems that the describe is giving me a filesort and a 30 second query execution : mysql> describe SELECT * FR...

1
голосов
1ответов
691 просмотров

LinqToSql - Include linked object in selected result

I have two tables. Linked with a foreign key. Now I fetch a row from the field table: IField Field = from f in DataContext.fields where f.mapId == mapId && f.x1 == x && f.y1 == y select f; Working with this row I need some data from the linked ...

1
голосов
2ответов
169 просмотров

Grouping records with or without a foreign key constraint

I have a table containing objects, something like this: PK ObjectId FK ObjectTypeId Description etc The objects need to be grouped. I have been given a number of suggestions, all of which 'work' and some I like more than others. None of them are perfect so I'm struggling to settle on any par...

1
голосов
1ответов
1315 просмотров

Mysql mapping table FK constraints

I'm experiencing some difficulties with foreign key constraints. I have three tables: Features ID PK AUTO_INC Title VARCHAR Subscriptions ID PK AUTO_INC Title VARCHAR Subscriptionfeatures ID PK AUTO_INC feature_id INT (index) subscription_id INT (index) When I have ...

0
голосов
1ответов
252 просмотров

why can not add this foreign key?

I have this schema: CREATE TABLE `lotto`.`combinaciones` ( `indice` mediumint(8) unsigned NOT NULL, `binario` int(10) unsigned NOT NULL, PRIMARY KEY USING BTREE (`indice`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `lotto`.`sorteo` ( `numeroSorteo` int(11) NOT NULL, `fechaSo...

6
голосов
1ответов
30135 просмотров

Hibernate: Foreign key has the wrong number of columns

I have defined a many-to-many relationship between my two entity classes User and Permission. User has a primary key composite of username and countyId, and my Permission table has a regular integer Id. The table UserPermission has the three foreign keys as its primary key: username, countyId and...

428
голосов
7ответов
315450 просмотров

When to use "ON UPDATE CASCADE"

I use "ON DELETE CASCADE" regularly but I never use "ON UPDATE CASCADE" as I am not so sure in what situation it will be useful. For the sake of discussion let see some code. CREATE TABLE parent ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ); CREATE TABLE child ( id INT NOT N...

1
голосов
1ответов
2023 просмотров

SQL foreign keys with multiple tables

If I have three tables: music_genres ----------- music_type_id genres [other unique fields] minerals -------- mineral_id mineral [other unique fields] verbs ----- verb_id verbs [other unique fields] and these are populated with: rock jazz funk punk rock boulder stone shale rock wobble sha...

2
голосов
5ответов
227 просмотров

What is the accepted method to delete records referenced by a junction/join table?

I have three tables as follows, with NO cascading relationships (I do not want this, as the database is primarily managed by NHibernate). Invoice ( entity_id int not null, ... ) Ticket ( entity_id int not null, ... ) InvoiceTicket ( InvoiceId --> Not-null foreign key to ...

7
голосов
1ответов
6854 просмотров

How can I load HABTM-with-foreign-key relationships in my fixtures?

I have the following two models: School and User, and a HABTM relationship between them, with a join table. In this join table, the foreign key refering to the User table is not called user_id but student_id. class School < ActiveRecord::Base has_and_belongs_to_many :students, :class_name ...

2
голосов
4ответов
3723 просмотров

PostgreSQL, Foreign Keys, Insert speed & Django

A few days ago, I ran into an unexpected performance problem with a pretty standard Django setup. For an upcoming feature, we have to regenerate a table hourly, containing about 100k rows of data, 9M on the disk, 10M indexes according to pgAdmin. The problem is that inserting them by whatever me...

3
голосов
2ответов
1215 просмотров

Are MySQL Foreign Key auto-generated names deterministic?

When constraints are created they are given names that look something like this 'FK5E6B788655A1514E'. I'm wondering if the name generation is deterministic or random. I noticed that two separate databases I was using, same schemas, ended up with the same FK names. Does it make sense when writin...

98
голосов
20ответов
126208 просмотров

MySQL Creating tables with Foreign Keys giving errno: 150

I am trying to create a table in MySQL with two foreign keys, which reference the primary keys in 2 other tables, but I am getting an errno: 150 error and it will not create the table. Here is the SQL for all 3 tables: CREATE TABLE role_groups ( `role_group_id` int(11) NOT NULL `AUTO_INCREMEN...

7
голосов
4ответов
3694 просмотров

Multiple foreign keys to the same table

I have a reference table with all sorts of controlled value lookup data for gender, address type, contact type, etc. Many tables have multiple foreign keys to this reference table I also have many-to-many association tables that have two foreign keys to the same table. Unfortunately, when these ...

2
голосов
1ответов
1661 просмотров

Any support for foreign keys in CakePHP schema shell or migrations?

I'm new to CakePHP, and I'm trying to decide between the schema shell that comes with CakePHP and the migrations tools that were written by Joel Moss and Georgi Momchilov. So far I haven't found any direct support in either of them for creating foreign key constraints. It appears that you might ...

1
голосов
1ответов
320 просмотров

LinqToSql is trying to insert a foreign key child when it already exists over WCF. What can I do?

I'm having trouble inserting a new LinqToSql object over WCF. What I'm doing is just sending an Orders Batch to the service. Inside the batch are Orders that have already been sent previously. When I do data.batches.InsertOnSubmit(newbatch) I get a SQL error: "Violation of PRIMARY KEY cons...

0
голосов
1ответов
253 просмотров

SubSonic 3 ActiveRecord migration ignores foreign keys

Using SubSonic 3 ActiveRecord, I generated code from an existing database that had foreign keys. To ensure database schema is always correct when switching databases, I placed migration code at the beginning of the app, using IDataProvider.MigrateToDatabase<MyClass>() for each class generat...

15
голосов
6ответов
9896 просмотров

How can I find unindexed foreign keys in SQL Server

I have a SQL Server 2000 database with approximately 220 tables. These tables have a number foreign key relationships between them. Through performance analysis, we've discovered a number of these foreign key relationships are missing indexes. Instead of being reactive to performance problems,...

1
голосов
1ответов
2019 просмотров

django: manually adding a foreign key column (newcolumn_id_refs_id_4bfb2ece ?)

I need to add a foreign key field to an existing django model/postgres table. As per the django documentation, I ran the 'sqlall myapp' command to 'work out the difference'. The obvious difference is that the table in question now has an extra column with a new contraint, which looks like this:...

1
голосов
1ответов
372 просмотров

Merging identical tables but maintaining separate referential integrity

Consider a dimensional model with fact tables like (fk_dim1value, fk_dim2value, ..., value) where the fk_X columns are foreign keys into corresponding trivial dimension tables dim1value (id, value), dim2value (id, value), etc. These fact-and-dimension tables are collected automatically from disp...

-1
голосов
1ответов
3154 просмотров

Foreign key constraints while dumping data

mysqldump --compact --no-create-info -h192.168.150.180 -uroot -p live pnlbus_stops | sed s/pnlbus_stops/bus_stops/g | mysql test I am getting an error: ERROR 1062 (23000) at line 1: Duplicate entry 'AN' for key 1 This is because bus_stops table in the test DB has foreign key constraints. How d...

8
голосов
2ответов
6315 просмотров

Grails - multiple belongsTo of same class with cascading deletion

This one is for the Grails users here. I asked it on the grails - user mailing list, but I figured since I've been fighting this for a couple of days I should cast as wide a net as possible. I'm having some difficulty with trying to model relationships between two objects of the same type in an...