foreign-keys

Posting data to create related Tastypie resources simultaneously?

天涯浪子 提交于 2019-12-04 17:14:27
Given two related Django models A and B in a OneToMany relationship: models.py class A(models.Model): name = models.CharField(max_length=5) class B(models.Model): name = models.CharField(max_length=5) a = models.ForeignKey(A) And given (potentially non-optimal) Tastypie resources: api.py class AResource(ModelResource): bs = fields.ToManyField( 'projectname.api.BResource', 'bs', full = True) class Meta: queryset = A.objects.all() class BResource(ModelResource): a = fields.ToOneField( AResource, 'a', full = True) class Meta: queryset = B.objects.all() Let's assume the database is empty so far.

Do you absolutely need foreign keys in a database?

血红的双手。 提交于 2019-12-04 17:11:26
问题 I was wondering how useful foreign keys really are in a database. Essentially, if the developers know what keys the different tables depend on, they can write the queries just as though there was a foreign key, right? Also, I do see how to foreign-key constraints help prevent all sorts of bugs with data integrity, but say for example, the programmers do a good job of preserving data integrity, how necessary are foreign keys really? 回答1: If you don't care about referential integrity then you

Deleting from multiple tables with foreign constraints

老子叫甜甜 提交于 2019-12-04 15:52:28
问题 I am trying to delete from multiple tables. Here's what my tables look like A_has_B ---- B ---- C_has_B (many to many) (many to many) I am trying to delete all rows from A_has_B, B and C_has_B given the ID of a record in B. I am using MySQL with the innodb storage engine with foreign keys defined for A_has_B and C_has_B referencing the IDs in B. I am trying to perform my delete like so: DELETE A_has_B.*, C_has_B.*, B.* FROM A join B on (B.B_id = A.B_id) join C on (C.B_id = B.B_id) where B.B

Refactor SQLite Table by splitting it in two and link with foreign keys

谁说胖子不能爱 提交于 2019-12-04 15:36:51
I'm working on a SQLite Database. The database is already filled, but I want to refactor it. Here is a sample of what I need to do: I currently have one table: CREATE TABLE Cars (ID INTEGER PRIMARY KEY, Name VARCHAR(32), TopSpeed FLOAT, EngineCap FLOAT); I want to split this into two tables: CREATE TABLE Vehicles (ID INTEGER PRIMARY KEY, Name VARCHAR(32), TopSpeed FLOAT); CREATE TABLE Cars (ID INTEGER PRIMARY KEY, VehicleID INTEGER CONSTRAINT FK_Cars REFERENCES [Vehicles](ID), EngineCap FLOAT); I have figured out to create a temporary table with the Cars table contents, and I can fill up the

referential integrity in rails

≯℡__Kan透↙ 提交于 2019-12-04 14:10:42
So, I just came across the fact that rails does not support referential integrity regarding foreign keys and was fairly surprised. So, what's the best way to manage this? Is there a "rails" way for dealing with referential integrity? Ideally the app should not have to deal with all this; the db should. I was looking at plugins like foreigner. I wonder if this method has some shortcomings. How is this normally dealt with in rails? It's a design decision for Rails ActiveRecord. I consider stored procedures and constraints vile and reckless destroyers of coherence. No, Mr. Database, you can not

Does the foreign keys automatically get updated as primary table is updated?

☆樱花仙子☆ 提交于 2019-12-04 13:30:04
问题 Above is my simple database design, just wanted to gain information about how things happen as I'm really new at database. Following are my questions: as I update wall_id in walls table, does the wall_id in wall_categories table also get updated? as the wall_id in wall_categories table references to wall_id in walls table. same with desktop_id in walls table since it is a foreign key referencing to desktop_id in desktop_wall table, so when I update desktop_id in walls table does the desktop

Multiple Foreign Keys for a Single Record in Rails 3?

我只是一个虾纸丫 提交于 2019-12-04 13:21:31
问题 I am working on an app that will manage students enrolled in a course. The app will have users who can log in and manipulate students. Users can also comment on students. So three of our main classes are Student, User, and Comment. The problem is that I need to associate individual comments with both of the other models: User and Student. So I've started with some basic code like this... class Student < ActiveRecord::Base has_many :comments end class User < ActiveRecord::Base has_many

How to find all foreign keys?

回眸只為那壹抹淺笑 提交于 2019-12-04 13:13:14
I'd like to find all referencing tables in my db that have a foreign key that points to a specific referenced table. Is there a query that I can run to do this? Not sure if the question is confusing. Let me know if it is and I can try to explain it in more detail. The following query or Modification tehreof will do - in Sql server You can also supply catalog and schema info select tab1.TABLE_NAME from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as ref inner join INFORMATION_SCHEMA.TABLE_CONSTRAINTS as prim on ref.UNIQUE_CONSTRAINT_NAME=prim.CONSTRAINT_NAME and ref.UNIQUE_CONSTRAINT_CATALOG=prim

Disappearing Foreign Keys in phpMyAdmin

笑着哭i 提交于 2019-12-04 12:14:19
问题 I am creating a new table inside mysql and I am trying to add a foreign key constraint to one of the fields. CREATE TABLE `onlineorder` ( `receiptid` varchar(10) NOT NULL default '', `delivereddate` date default NULL, `cid` int(10) NOT NULL, `card#` int(10) default NULL, `expire` date default NULL, PRIMARY KEY (`receiptid`), FOREIGN KEY (receiptid) REFERENCES purchase ) ENGINE=MyISAM DEFAULT CHARSET=latin1; However, after it creates it, I go into phpMyAdmin and export the table. and it seems

Entity Framework Foreign Key Mapped to Same Table

喜你入骨 提交于 2019-12-04 12:12:33
This is not a duplicate of this post although the title is very similar. I am using EF4 with MSSQL Express 2008 R2 on VS2010. A simplified version of my schema is as follows: Table [Team]: Id (PK) Member1 Member2 Table [Person]: Id (PK) FirstName [Team].Member1 and [Team].Member2 are foreign keys pointing to [Person].Id. When generating the .edmx via VS2010, the navigation properties under [Team] become "Person" and "Person1" despite giving distinct names to the FKs inside SQLServer. Is it possible to force the .edmx generator to recognize my FK names in SQL Server? I'd like these names to be