foreign-keys

With SubSonic is there a way to express relationships without foreign keys?

半世苍凉 提交于 2019-12-11 05:49:22
问题 Our database does not have foreign keys, but we wish to be able to use SubSonic. Are there any ways except for foreign keys to express relationships between tables? Also see this related question 回答1: There are three possible solutions that come to my mind: a) The hard way: Do everthing yourself Every class that is generated by SubSonic is a partial class. You can create a new file and add the properties methods for ForeignKey relation yourself: partial class Order { private

Entity Framework POCO with Foreign keys

一个人想着一个人 提交于 2019-12-11 05:26:17
问题 My question can better be explained via example code. I am using POCO with change tracking proxies that is generated by the C# POCO generator by default. Please see below. Assume you have Movie, MusicDirector and Director in the database and the relationship between them is a Director & MusicDirector can direct multiple movies and a movie can have only one Director and MusicDirector. Since I am a new user and cannot post images, here is my db structure. Movie table has MovieId, Name

MySql query limiting and ordering on join statament

杀马特。学长 韩版系。学妹 提交于 2019-12-11 05:23:49
问题 I have a two tables as authors and articles. I want to get list of latest articles for each author. I want only one article for one author. And I want it to be the latest. But, I couldn't even figure out where to start to this sql query. Edit My table structure can be simplefied like this: authors: id name status seo articles: author_id title text date seo Edit 2 I came up with something like this, is there any obvious mistakes you can see in here: SELECT authors.*, (SELECT articles.title

Can I add a check constraint to a child checking the value of its parent in MySQL?

百般思念 提交于 2019-12-11 05:16:22
问题 I have a similar database with two tables as follow: +----------------------+ +------------------------+ |Persons | |phones | +----------------------+ +------------------------+ |id int +-----+ |id int | |name varchar(100) | +---->+person_id int | |allowed tinyint(1) | |number int | +----------------------+ +------------------------+ One person could have as many phones as he wants but he has to be allowed to it (allowed > 0). So, I created both tables using CREATE TABLE `phones` ( `id` int

Creating relationship to non-primary column

≡放荡痞女 提交于 2019-12-11 05:09:50
问题 I have a table which references a foreign key to its main table. But I want to add an other reference to another table. For instance, let's suppose I have three tables: Child, Parent, Transaction Parent table: ParentID Child table: ChildID ParentID Transaction table: TransactionID ParentID (references ParentID on Parent table, nullable ) ChildID (references ChildID on Child table, nullable ) I want to add a cascade on update reference to ParentID on Child table. So that when a relationship

In a SQL database, when should a one-to-one relationship be in the same table and when in separate tables?

风格不统一 提交于 2019-12-11 04:56:49
问题 Can anyone provide some examples of when in a SQL database it's a better choice to keep one-to-one relationships on the same table, and when instead it makes more sense to have them on separate tables? 回答1: When you have several entities which all must be able to act as a foreign key to another entity, and the "several entities" have both common properties and unique properties, and you want a NOT NULL constraint on the unique properties (or less important don't want a bunch of NULL values

insert value to foreign key

梦想的初衷 提交于 2019-12-11 04:35:54
问题 problem is with foreign key: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_uzytkownik_Logowanie". The conflict occurred in database "Restauracja", table "dbo.Logowanie", column 'LoginID'. The statement has been terminated. I check this using breakpoints, and primary key in Logowanie table was added when breakpoints (running application) was after baza.SubmitChanges(); Primary key of LoginID in logowanie table is added automatically during SubmitChanges . How to copy

Django Filter by latest related object

让人想犯罪 __ 提交于 2019-12-11 04:27:43
问题 I've setup a system to track moderation tasks for various objects in the database. These are linked via a Generic Foreign Key relation. Given a ObjectModerationState Object I must determine its state from the most recent StateTransisition object. The solution must lend it self to be used in a SimpleListFilter for sorting on list_display using list_filter. e.g. Given States - Queued - Completed - Verify I should be able to filter ObjectModerationState Objects, based on the latest state value

Error while adding Foreign key

偶尔善良 提交于 2019-12-11 04:15:16
问题 I am using Mysql Workbench. I have already made the table. Now I want to add foreign key in a table called Personal_Details that key is primary key in Login table. But when I am trying to do so, it shows me the following error: ERROR 1005: Can't create table 'shaadiDB.#sql-404_25' (errno: 121) SQL Statement: ALTER TABLE `shaadiDB`.`Personal_Details` ADD CONSTRAINT `Login_Id` FOREIGN KEY (`Login_Id` ) REFERENCES `shaadiDB`.`Login` (`Login_Id` ) ON DELETE NO ACTION ON UPDATE NO ACTION , ADD

Basic logics with Django views and foreignkey

本小妞迷上赌 提交于 2019-12-11 04:12:37
问题 I am new to Django and struggling with a basic problem, yet cannot find a solution online. I have these models: class Suggestion(models.Model): author = models.ForeignKey('auth.User') title = models.CharField(max_length=200) description = models.TextField() created_date = models.DateTimeField(default=timezone.now) def __str__(self): return self.title class Vote(models.Model): suggestion = models.ForeignKey(Suggestion) voter = models.ForeignKey('auth.User') vote_count = models.IntegerField