relational-database

Trouble handling generic relationship in django

一笑奈何 提交于 2019-12-24 11:12:51
问题 I want to model a situation and I´m having real trouble handling it. The domain is like this: There are Posts, and every post has to be associated one to one with a MediaContent. MediaContent can be a picture or a video (for now, maybe music later). So, what I have is: mediacontents/models.py class MediaContent(models.Model): uploader = models.ForeignKey(User) title = models.CharField(max_length=100) created = models.DateTimeField(auto_now_add=True) def draw_item(self): pass class Meta:

Changes in data and their effect on historical data

旧时模样 提交于 2019-12-24 07:26:20
问题 Say you have an simple CRM system with customers and orders. If a customer changes his name, will you prefer that the old historical orders get the new name as well, or do you copy it to a string value on the order to preserve the accuracy? I doubt there is an answer that covers all situations, but I'm struggling with deciding where I can accept the historical data to be changed and where I cannot accept it. Generally I'm using the thought that if it can be printed, it must be printable again

Database design - should two projects share the same table?

雨燕双飞 提交于 2019-12-24 04:03:10
问题 Background: Two projects (A & B) under design at the same time both needs a new table(called DocumentStore ) to store document/file under postgres. But business logic around the document storage are different between project A & B, this means relationship around DocumentStore are different between A & B. Let's make this a bit more concrete, see example below: The Document storage table structure looks the same without constraints/ foreign Keys: Table DocumentStore DocUUID //unique Id for this

Relational Database Mapping in MVC

拟墨画扇 提交于 2019-12-24 01:19:08
问题 I apologize for the amount of code but I just need some confirmation of my mapping and usage of [ForeignKey("XXX") is correct or not. In classes like Department and Depot do I need the lines public int DepartmentID { get; set; } or do they automatically number themselves when data is inserted in the database. (DepartmentID = 1 (Human Resources), DepotID = 2 (Los Angeles) This is my Entity Diagram. User.cs public class User { public int UserID { get; set; } [StringLength(50, MinimumLength = 1)

DataMapper can't delete record because of relation

微笑、不失礼 提交于 2019-12-24 01:04:52
问题 I have this many-many DataMapper/MySQL setup with Torrent and Tag, as follows: class Torrent include DataMapper::Resource property :id, Serial property :name, String property :magnet, Text property :created_at, DateTime has n, :tags, :through => Resource end class Tag include DataMapper::Resource property :id, Serial property :name, String property :hits, Integer has n, :torrents, :through => Resource end When trying to destroy a torrent, however, via Torrent.first.destroy or something

Relationship between the compositions of two entities which have N2N relationship between themselves

☆樱花仙子☆ 提交于 2019-12-23 16:31:06
问题 I have two entities defined: Product: ProductId (PK) Name (not null) Parts: PartId (PK) Name (not null) These have a many-to-many relationship defined between them. In my requirements I need to model another one-to-many relationship between the composite product/part item to some other composite product/part. In certain instances I also need to be able to link product without a part to product/part item. I have modeled it this way: ProductPartLink: ProductPartLinkId (PK) ProductId (not null)

What is the difference between REFERENCES with, or without a FOREIGN KEY

南楼画角 提交于 2019-12-23 10:57:31
问题 In regards to SQLite , What is the difference between REFERENCES with, or without a FOREIGN KEY? What is the difference between this CREATE TABLE players_set ( _id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, player_id INTEGER REFERENCES players ( _id ) ON DELETE CASCADE, players_set_id INTEGER REFERENCES players_set_names ( _id ) ); and this: CREATE TABLE players_set ( _id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, player_id INTEGER, players_set_id INTEGER REFERENCES players_set_names ( _id

Two way relationships in SQL queries

和自甴很熟 提交于 2019-12-23 09:18:21
问题 I have a small database that is used to track parts. for the sake of this example the table looks like this: PartID (PK), int PartNumber , Varchar(50), Unique Description , Varchar(255) I have a requirement to define that certain parts are classified as similar to each other. To do this I have setup a second table that looks like this: PartID , (PK), int SecondPartID , (PK), int ReasonForSimilarity , Varchar(255) Then a many-to-many relationship has been setup between the two tables. The

Would LIMIT 0,1 speed up a SELECT on a Primary Key?

萝らか妹 提交于 2019-12-23 09:06:27
问题 Does anyone know if there is any speed difference (obviously for tables that are sizable enough) between these two queries: SELECT field FROM table WHERE primary_key = "a particular value" or: SELECT field FROM table WHERE primary_key = "a particular value" LIMIT 0,1 I should note that the primary_key field is actually a primary key. Now LIMIT 0,1 does help when a query would otherwise carry on to find other matches. I'm assuming though that when a primary key is involved it should

set null value in a foreign key column?

只谈情不闲聊 提交于 2019-12-23 07:22:23
问题 I have this table CREATE TABLE [dbo].[CityMaster]( [CityID] [int] NOT NULL, [City] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [BranchId] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF__CityM__Branc__74444068] DEFAULT ((0)), [ExternalBranchId] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT [PK_CityMaster] PRIMARY KEY CLUSTERED ( [City] ASC, [BranchId] ASC ), CONSTRAINT [uk_citymaster_cityid_branchid] UNIQUE NONCLUSTERED (