foreign-keys

Why does referencing a SQLite rowid cause foreign key mismatch?

好久不见. 提交于 2019-12-01 14:18:37
问题 SQLite version 3.7.9 2011-11-01 00:52:41 sqlite> PRAGMA foreign_keys = 1; sqlite> CREATE TABLE foo(name); sqlite> CREATE TABLE bar(foo_rowid REFERENCES foo(rowid)); sqlite> INSERT INTO foo VALUES('baz'); sqlite> SELECT rowid, name FROM foo; 1|baz sqlite> INSERT INTO bar (foo_rowid) VALUES (1); Error: foreign key mismatch Why does this error occur? It is a DML error, but I don't know what's wrong because: foo exists. foo.rowid exists. foo.rowid is the primary key of foo and therefore

ForeignKey field related to abstract model in Django

时间秒杀一切 提交于 2019-12-01 14:14:37
问题 I have this model: class BaseModel(models.Model): .... class Meta: abstract = True class ModelA(BaseModel): .... class ModelB(BaseModel): .... class MyExtModel(models.Model) myfield = models.ForeignKey(BaseModel) But this is not correct because I have BaseModel like Abstract . Infact I have an error when I try makemigration command. The error is: ERRORS: myapp.MyExtModel.myfield: (fields.E300) Field defines a relation with model 'BaseModel', which is either not installed, or is abstract. Is

Advice on design relations between tables

邮差的信 提交于 2019-12-01 12:24:11
I have information about music albums that I want to organise in RDBMS tables with relations between them. I have the following info for each album: artist, album name, year, label, genre, style, rating. So far I think to make 4 tables - artists, albums (name, year, label, rating), genre1 and genre2 (each genre with its styles). On the diagram it looks as follows: But don't know yet how can I establish a connection between albums and the other three tables? I.e., when I will run a query select name from artists I would like to receive an album with corresponding artist and genre-style. How

Multiple Foreign Key to same table Gas Orm

我的梦境 提交于 2019-12-01 12:08:32
Since this mornong i am facing a very big problem. I am using CodeIgniter to develop a website, and GAS ORM for the database. I have basically two tables. One named "pool", and one named "partners". I am having two associations between these two tables, so I have two foreign keys in my table Partners referencing the table pool. Pool(#id:integer, name:varchar) Partners(#id:integer, associated_pool_id=>Pool, futur_associated_pool_id=>Pool). As I have two references to the same table, I can't name the foreign keys "pool_id". So in my relationships with Gas ORM, I have to specify the names of the

Are multiple foreign keys in a single field possible?

狂风中的少年 提交于 2019-12-01 09:38:35
I want to know if there is a way to have multiple values in a single field in a MySQL database where each value is a foreign key referencing one other table. I am designing a database with a product table and a product certification table. I am using InnoDB and foreign key constraints. The "product" table contains the details about specific instances of the product. One of the details contained in the product table is the column “product_certification_id”, which is a foreign key referencing an index in the two column “product_certification” table. The product certification table contains the

MySQL + PHP: fetching data using foreign keys

馋奶兔 提交于 2019-12-01 09:09:28
I have 2 tables (Users, Wall). The UserID in the Wall table is a foreign key. How would I go about fetching the users details using this? (I want to fetch the users Forename and Surname who posted the message.) Users Table: Wall Table: EDIT: I cannot figure out how to show the data. <?php include('config.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <title>Alpha</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <?php // Logged IN if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION[

SQL one-to-many

陌路散爱 提交于 2019-12-01 08:28:11
I am trying to build an SQL schema for a system where we have channels , each with an id , and one or more fixtures . I am having difficulty finding a way to implement this one-to-many mapping. (i.e. One channel to many fixtures ). I am using the H2 database engine . I cannot have a table : id | fixture ----|---------- 1 | 1 1 | 2 2 | 3 CREATE TABLE channel( id INT NOT NULL PRIMARY KEY, fixture INT NOT NULL ); ... as the PRIMARY KEY id must be UNIQUE . Similarly, I cannot map as follows: CREATE TABLE channel( id INT NOT NULL PRIMARY KEY, f_set INT NOT NULL REFERENCES fixtures(f_set) ); CREATE

Can I use the same foreign key constraint in two different tables?

若如初见. 提交于 2019-12-01 07:36:22
I am trying to create a database for work. I have two different types of users: internal and external. Each type has different properties so I just created two separate tables for them. In my internal table I have the following fields: f_name VARCHAR(32), l_name VARCHAR(32), empl_status_id INT, admin_grp_id INT, reliab_status_id INT, supv_id INT And my external table has the following: f_name VARCHAR(32), l_name VARCHAR(32), email VARCHAR(32), phone VARCHAR(20), org_id INT, supv_id INT I realize that I could probably create a separate table that contains the names of the users and a foreign

Multiple Column Foreign Key: Set single column to Null “ON DELETE” instead of all

末鹿安然 提交于 2019-12-01 07:34:15
问题 General : Given a foreign key over several columns, some of them might be NULL. By default (MATCH SIMPLE) MySQL/MariaDB InnoDB does not check the foreign key as long as at least one column of a multi column foreign key is NULL. Requirement : If a row is deleted from the parent one column of the corresponding child should be set to NULL, but not both columns in the foreign key. Example/Description : A student might be listed for a lecture, and optionally for one of the lectures groups as well.

Does SQLite coupled with NHibernate support referential integrity / foreign keys?

别来无恙 提交于 2019-12-01 06:42:37
I have been reading a bit about NHibernate with SQLite, figuring it might be a very good option when I need lightweight database handling. I've read the following (and the links) which talk about how the NHibernate SQLite dialect does not support foreign keys WHILE CREATING the database, since NHibernate creates foreign keys through ALTER TABLE . I'm wondering, if I create an SQLite database through some other tool, would I be able to use NHibernate with said SQLite database, would it honor the referential integrity? Enable referential integrity with nHIbernate using SQlite database NHibernate