foreign-keys

MySQL Syntax in creating Foreign Key

喜欢而已 提交于 2019-12-19 05:45:20
问题 Is this syntax correct in creating a Foreign Key? create table department ( departmentID int not null auto_increment primary key, name varchar(30) ) type=InnoDB; create table employee ( employeeID int not null auto_increment primary key, name varchar(80), job varchar(30), departmentID int not null references department(departmentID) ) type=InnoDB; 回答1: It looks like MySQL accepts it (doesn't complain about the syntax) but the foreign key is not actually created. To create this foreign key,

Relational database design - “cyclic” graphs

天大地大妈咪最大 提交于 2019-12-19 04:42:32
问题 In relational database design, should one worry about one (or more) "cyclic graphs" posing problems? (Simplified) E.g., tables T1( T1_Id , ...) T2( T2_Id , T1_Id_Fk, ...) T3( T1_Id_Fk, T2_Id_Fk , ..) Primary keys are bolded. Rows in T1 have a double role. A T1 row r1 can be in relationship T3 with a row r2 in T2, but it can also be a parent row for a (possibly the same) row r2' in T2. These two relationships are orthogonal. I came up with something like this: T1_Base( T1_Id , ...) T1_Child1(

Many to Many relationship in Asp.Net MVC 5 with Identity table and Custom table

此生再无相见时 提交于 2019-12-19 04:15:11
问题 I'm trying to make a relationship between the Users from the table generated by Asp.Net Identity with my own table. The relationship must be many to many, since many Users can work on the same Task (which is my table), and same time an User can work on multiple Tasks. public class Task { public int ID { get; set; } public string Name { get; set; } public string UserID { get; set; } public virtual ICollection<ApplicationUser> Users { get; set; } } public class ApplicationUser : IdentityUser {

Does MySQL InnoDB always require an index for each foreign key constraint?

瘦欲@ 提交于 2019-12-19 03:56:10
问题 I am using phpMyAdmin. In order to set up a foreign key constraint with InnoDB (under the "Relation View" link on the Structure tab) it appears that I need to add an index for the field to which I want to add the restraint. This obviously has an impact on performance of inserts/updates on the table, particularly if there are several constraints I want to add. Is it possible to specify a foreign key constraint or relational integrity in InnoDB without the need to create an Index for the

Is is possible to get new values for Id (IDENTITY) before inserting data in a table?

你。 提交于 2019-12-19 03:36:46
问题 Is is possible to get new values for Id (IDENTITY) before inserting data in a table ? Is is possible to write something like that : INSERT INTO Table1 SELECT *GET_NEW_IDENTITY*, Field1, Field2 FROM Table2 I need the values of Id because I want to insert data in Table1 and, just after, insert data in another table which has a foreign key linked to Table1 (with Id) 回答1: IDENT_CURRENT . Returns the last identity value generated for a specified table or view. The last identity value generated can

Django auth.User in Admininterface: coercing to Unicode: need string or buffer, User found

梦想与她 提交于 2019-12-19 03:07:16
问题 I'm pretty new to django. I try to use the auth.User object as a foreign key. My model: from django.contrib.auth.models import User (...) class Entry(models.Model): (...) user = models.ForeignKey(User) date = models.DateTimeField() def __unicode__(self): return self.user When creating a new Entry with a user in admin interface, i get: "coercing to Unicode: need string or buffer, User found" Exception Type: TypeError Exception Value: coercing to Unicode: need string or buffer, User found

NHibernate sets Foreign Key in secondary update rather than on initial insert violating Not-Null Constrain on key column

送分小仙女□ 提交于 2019-12-19 03:04:07
问题 I am having a problem with what should be a fairly simple (I would think) NHibernate use case. I have a classic Parent and a Child entity like so: public class Parent { public virtual int ParentId { get; set; } public virtual string Name { get; set; } public virtual IList<Child> Children { get; set; } } public class Child { public virtual int ChildId { get; set; } public virtual Parent Parent { get; set; } public virtual string Name { get; set; } } And mappings as follows: public class

NHibernate sets Foreign Key in secondary update rather than on initial insert violating Not-Null Constrain on key column

时间秒杀一切 提交于 2019-12-19 03:04:06
问题 I am having a problem with what should be a fairly simple (I would think) NHibernate use case. I have a classic Parent and a Child entity like so: public class Parent { public virtual int ParentId { get; set; } public virtual string Name { get; set; } public virtual IList<Child> Children { get; set; } } public class Child { public virtual int ChildId { get; set; } public virtual Parent Parent { get; set; } public virtual string Name { get; set; } } And mappings as follows: public class

How to use “central columns” in phpmyadmin?

心已入冬 提交于 2019-12-19 02:02:35
问题 PMA has the tools for adding the central columns. As far as I understand, it's used with foreign constraints. I have two tables: TableA and TableB . Structure of TableA : id_of_A , name_of_A_value , ... Structure of TableB : id_of_B , foreign_id_of_A , ... and foreign constraint from foreign_id_of_A to A-table . id_of_A . And it's very difficult to select needed foreign_id_of_A while insert new row into TableB because only value of id_of_A is visible. Could central columns help me with this

Django File Upload and Rename

半世苍凉 提交于 2019-12-19 00:56:30
问题 User is uploading a .c file of a particular question. I want the file to be renamed as 'userid_questionid.c' My models.py is : from django.db import models class users(models.Model): username = models.CharField(max_length=20) password = models.CharField(max_length=20) score=models.IntegerField(max_length=3) def __unicode__(self): return self.username class questions(models.Model): question = models.TextField(max_length=2000) qid=models.IntegerField(max_length=2) def __unicode__(self): return