foreign-keys

Django isn't creating db constraints for foreign keys with SQLite

故事扮演 提交于 2020-06-01 05:05:52
问题 I'm using Django 3.0.6 I'm adding ForeignKey and ManyToManyField to my models, but I've noticed that django creates the INDEX , but not the actual FOREIGN KEY constraints in the db. I've tried to explicitly set db_constraint=True but as expected is useless, since it's True by default. I've found so many answers explaining this, but only for very old Django versions, doing tricks for enabling it when it was otherwise disabled. Now instead it should just work out of the box. Couldn't find

Linear database design

懵懂的女人 提交于 2020-05-29 09:55:45
问题 I have a question about database relationship I am trying to build a monitoring system with the following rules : Channels belongs to one Sensor Sensors belongs to one Device Devices belongs to one Probe Probes belongs to one Core Here is a preview of the tables +-------------+ +-------------+ | Cores | | Probes | +-------------+ +-------------+ | id | | id | | fields ... | | fields ... | +-------------+ | core_id | +-------------+ +-------------+ +-------------+ +-------------+ | Devices | |

Linear database design

孤者浪人 提交于 2020-05-29 09:53:06
问题 I have a question about database relationship I am trying to build a monitoring system with the following rules : Channels belongs to one Sensor Sensors belongs to one Device Devices belongs to one Probe Probes belongs to one Core Here is a preview of the tables +-------------+ +-------------+ | Cores | | Probes | +-------------+ +-------------+ | id | | id | | fields ... | | fields ... | +-------------+ | core_id | +-------------+ +-------------+ +-------------+ +-------------+ | Devices | |

How to extract cross databases references using scriptdom API

情到浓时终转凉″ 提交于 2020-05-23 09:50:29
问题 Microsoft has exposed the scriptdom API to parse and generate TSQL. I'm new to it and still playing with it. I want to know how to get the cross databases references from queries like this one. UPDATE t3 SET description = 'abc' FROM database1.dbo.table1 t1 INNER JOIN database2.dbo.table2 t2 ON (t1.id = t2.t1_id) LEFT OUTER JOIN database3.dbo.table3 t3 ON (t3.id = t2.t3_id) INNER JOIN database2.dbo.table4 t4 ON (t4.id = t2.t4_id) What I want is a list of the references: database1.dbo.table1.id

django updating foreignKey field before saving

99封情书 提交于 2020-05-16 21:57:22
问题 I have the following models.py class Notebook(models.Model): category = models.ForeignKey(Category) title = models.CharField(max_length=200, help_text='Maximum 250 characters') slug = models.SlugField(unique=True) last_modified = models.DateTimeField() def __unicode__(self): return self.title class Page(models.Model): Notebook = models.ForeignKey(Notebook) title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') tags = TaggableManager() pub_date = models

django updating foreignKey field before saving

南楼画角 提交于 2020-05-16 21:55:26
问题 I have the following models.py class Notebook(models.Model): category = models.ForeignKey(Category) title = models.CharField(max_length=200, help_text='Maximum 250 characters') slug = models.SlugField(unique=True) last_modified = models.DateTimeField() def __unicode__(self): return self.title class Page(models.Model): Notebook = models.ForeignKey(Notebook) title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') tags = TaggableManager() pub_date = models

How to set “auto insert” foreign key value by using SQL Server?

孤者浪人 提交于 2020-05-16 20:36:05
问题 I have created two tables and also created a relationship between them. Table students : create table students ( [StudentId] NVARCHAR(50) NOT NULL PRIMARY KEY, [Name] NVARCHAR(50) NOT NULL ); Table studentprofile : create table studentprofile ( [Id] INT NOT NULL PRIMARY KEY IDENTITY(1, 1), [StudentId] NVARCHAR(50) NOT NULL, [Address] NVARCHAR(50) NOT NULL, ); and relationship: alter table studentprofile add constraint students_studentprofile_FK foreign key (StudentId) references students

NULL values for referential_constraints.unique_constraint_* columns in information schema

风流意气都作罢 提交于 2020-05-09 06:47:29
问题 In Postgres 10 I have declared the following: create table test_abc ( pk integer not null, id integer not NULL, id2 integer not null, PRIMARY KEY (pk) ); CREATE UNIQUE INDEX test_abc_ids ON test_abc(id,id2); And then a second table with a FK referencing the first: create table test_def ( id integer not null, abc_id integer, abc_id2 integer, PRIMARY KEY (id), FOREIGN KEY (abc_id,abc_id2) references test_abc(id,id2) ); Now consider the output of this query: SELECT unique_constraint_catalog,

Constraint to prevent violation of FK constraint in a third table

跟風遠走 提交于 2020-03-09 05:39:48
问题 I can implement the constraints that I want in stored procs, but I'm wondering if I can define a set of foreign key constraints which will do the job. I have several tables, with these key relationships: NSNs --- Id PK Solicitations ---- Id PK NSNId FK - NSNs Parts ----- Id PK NSNId FK - NSNs BaseRFQs ------- Id PK NSNId FK - NSNs RFQs ---- Id PK BaseRFQId FK - BaseRFQs BaseRFQsSols ------------ BaseRFQId PK/FK - BaseRFQs SolId PK/FK - Solicitations RFQsSolsParts ------------- RFQId PK/FK -

sequelize foreign key returning as “Null”

心不动则不痛 提交于 2020-03-05 11:56:34
问题 I have added foreign keys to my project using sequelize. User is the parent table and profile_personals is the child table. When I post something the foreign key comes out as NULL. I'm trying to create it so when I post something through postman it can grab the User id Automatically. db.js file const db = {}; db.sequelize = sequelize; db.Sequelize = Sequelize; // Models db.Users = require('../model/User.js')(sequelize, Sequelize); db.Personal = require('../model/profile_personal.js')