foreign-keys

foreign key and index issue

浪尽此生 提交于 2019-12-10 11:18:10
问题 I am using SQL Server 2008 Enterprise. I have a table and one of its column is referring to another column in another table (in the same database) as foreign key, here is the related SQL statement, in more details, column [AnotherID] in table [Foo] refers to another table [Goo]'s column [GID] as foreign key. [GID] is primary key and clustered index on table [Goo]. My question is, in this way, if I do not create index on [AnotherID] column on [Foo] explicitly, will there be an index created

Add inline model to django admin site

心不动则不痛 提交于 2019-12-10 11:16:44
问题 I have this two models: class Rule(models.Model): name = models.CharField(max_length=200) class Channel(models.Model): id = models.CharField(max_length=9, primary_key=True) name = models.CharField(max_length=100) rule = models.ForeignKey(Rule, related_name='channels', blank=True) And I have to be able to add channels to rule in admin site within RuleAdmin interface. So I created this two admin models: class ChannelAdmin(admin.TabularInline): model = Channel class RuleAdmin(admin.ModelAdmin):

Laravel 5.3 Eloquent transactions and foreign key restrictions

♀尐吖头ヾ 提交于 2019-12-10 10:56:58
问题 Am working on bigger project where we have multiple schemas in one Postgres DB. We have created foreign keys between schemas. Here is an example > We have company schema and user schema. Company schema has company_users table which have foreign key restriction on user.users table CREATE TABLE company.company_user ( id serial NOT NULL, company_id integer NOT NULL, user_id integer NOT NULL, created_at timestamp(0) without time zone, updated_at timestamp(0) without time zone, deleted_at

Double Foreign Key in Django?

空扰寡人 提交于 2019-12-10 09:57:28
问题 Is there anyway to model double foreign keys in Django? For instance if I had tables: audio, overlay, html and the table: timeline_item which has a field id, and a field category which specifies audio, overlay, or html... Does anyone know how I would go about modeling this in Django? or if it's even possible? 回答1: Sounds like a polymorphic association. Maybe you can solve your problem with Django's generic relations using the ContentTypes framework. 回答2: Foreign key is referential constraint

ORA-00904: “ID”: invalid identifier

◇◆丶佛笑我妖孽 提交于 2019-12-10 09:54:53
问题 Trying to create a table with a foreign key. I keep getting ORA-00904 error. What am I doing wrong. Is it because table of the foreign key is not yet created ? CREATE TABLE ingredients( ingredient_id number(2,0), ingredient VARCHAR2(55) NOT NULL, quantity_required VARCHAR2(15) NOT NULL, optional_ingredient VARCHAR2(30) NOT NULL, CONSTRAINT pk_ingr_id PRIMARY KEY(ingredient_id), CONSTRAINT fk_ingredient_list FOREIGN KEY(id) REFERENCES ingredient_list(id) ); 回答1: Take a look at the following

Implementing foreign key type relationships in XSD schema

巧了我就是萌 提交于 2019-12-10 09:41:55
问题 I'm trying to wrap my head around xml schemas and one thing I'm trying to figure out is how to do relational type schemas where on element refers to another, possibly in another schema altogether. I've looked at the xsd:key and xsd:keyref and it seems like the sort of thing I'm interested in, but I'm not sure. Initially I just set attributes with the type xs:ID abd xs:IDREF, which obviously doesn't necessarily refer to a specific element as far as I could tell. Basically, I have several

How to reference two tables in Visual Studio 2012 by adding foreign key?

情到浓时终转凉″ 提交于 2019-12-10 09:33:17
问题 I have a problem adding a foreign key to a table column. My tables look this way. I need to reference ContactOwnerId from Contact table to UserId in UserProfile table CREATE TABLE [dbo].[Contacts] ( [ContactId] INT IDENTITY (1, 1) NOT NULL, [ContactOwnerId] INT NOT NULL, [FirstName] NVARCHAR (MAX) NOT NULL, [LastName] NVARCHAR (MAX) NOT NULL, [Address] NVARCHAR (MAX) NOT NULL, [City] NVARCHAR (MAX) NOT NULL, [Phone] NVARCHAR (MAX) NOT NULL, [Email] NVARCHAR (MAX) NOT NULL, CONSTRAINT [PK_dbo

MySQL attempting to delete all rows which are not constrained by foreign key

二次信任 提交于 2019-12-10 09:31:51
问题 Okay, this is (probably) a very simple question, but I am afraid I know almost no MySQL, so please put up with me. I'm just trying to delete every row from one table which is not constrained by a Foreign Key in another table - a specific table, there are only two tables involved here. The create statements look a bit like: CREATE TABLE `testschema`.`job` ( `Job_Id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Comment` varchar(255) DEFAULT NULL, PRIMARY KEY (`Job_Id`) USING BTREE, ) ENGINE

django.db.utils.IntegrityError: FOREIGN KEY constraint failed while executing LiveServerTestCases through Selenium and Python Django

天大地大妈咪最大 提交于 2019-12-10 09:24:02
问题 I can run all unit tests successfully, I can even run selenium tests successfully if I run an independent server, but when I try to use LiveServerTestCases to test everything in a self-contained manner, each LiveServerTestCase test ends with the following error after completing the tearDown function: File "C:\Users\Win7\.virtualenvs\lang-QbOXb8q_\lib\site-packages\django\db\backends\base\base.py", line 239, in _commit return self.connection.commit() django.db.utils.IntegrityError: FOREIGN KEY

Dynamically limit choices for Foreignkey in Django models based on another foreign key in the same model

落爺英雄遲暮 提交于 2019-12-10 08:52:05
问题 I have these models: class UserProfile(models.Model): name = models.CharField(max_length=100) class Dialog(models.Model): belong_to = models.ManyToManyField(UserProfile) class Message(models.Model): # Dialog to which this message belongs part_of = models.ForeignKey(Dialog) # User who sends message sender = models.ForeignKey(UserProfile, related_name='sender') # User who receives message receiver = models.ForeignKey(UserProfile, related_name='receiver') What I want to do is limit the choices