foreign-keys

Problem creating foreign keys in mySql

点点圈 提交于 2019-12-23 02:54:15
问题 I created a foreign key in my sql by the following statemnt.. ALTER TABLE `users` ADD FOREIGN KEY ( `id`) REFERENCES `user_login` (`user_id`) ON DELETE CASCADE ; The creation appears to succeed then after that I execute a delete statement DELETE From user_login WHERE user_id = 1576; yet in users the row still exists that is referencing that. I open up the mysql workbench and it doesn't show any signs that the foreign key was created. Does anyone know why this would be? Or what I am doing

play framework - SQLite: Enable Foreign Key

不打扰是莪最后的温柔 提交于 2019-12-23 02:19:43
问题 I have a problem when using SQLite with play, SQLite documentation says that foreign keys are disabled by default, and need to be enabled with each connection. I am using SQLite with Ebean, in evolution I added this line: PRAGMA foreign_keys = ON; but It doesn't work, it only works when I open a connection from terminal or SQLite Client and execute that line ( PRAGMA foreign_keys = ON; ), I also tried this in the start of the app but with no luck: Ebean.getServer("mom").createSqlUpdate(

PostgreSQL - Check foreign key exists when doing a SELECT

徘徊边缘 提交于 2019-12-23 02:13:12
问题 Suppose I have the following data: Table some_table : some_table_id | value | other_table_id -------------------------------------- 1 | foo | 1 2 | bar | 2 Table other_table : other_table_id | value ---------------------- 1 | foo 2 | bar Here, some_table has a foreign key to column other_table_id from other_table into the column of some name. With the following query in PostgreSQL: SELECT * FROM some_table WHERE other_table_id = 3; As you see, 3 does not exists in other_table This query

Mysql errno 150 trying to create table with foreign key references

狂风中的少年 提交于 2019-12-22 10:48:41
问题 I'm trying to create a table in mysql with a foreign key reference, like this: In database A: CREATE TABLE replication ( id varchar(255) NOT NULL PRIMARY KEY, uid varchar(255) NOT NULL, value int(11) NOT NULL, FOREIGN KEY (uid) REFERENCES databaseB.users(username) ); In database B i have a table named users like this: +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+------

SQL - NULL foreign key

被刻印的时光 ゝ 提交于 2019-12-22 09:55:10
问题 Please have a look at the database design below: create table Person (id int identity, InvoiceID int not null) create table Invoice (id int identity, date datetime) Currently all persons have an invoiceID i.e. the InvoiceID is not null . I want to extend the database so that some person does not have an Invoice . The original developer hated nulls and never uses them. I want to be consistent so I am wondering if there are other patterns I can use to extend the database to meet this

Multiple Foreign keys to a single table and single key pointing to more than one table

梦想与她 提交于 2019-12-22 09:25:33
问题 I need some suggestions from the database design experts here. I have around six foreign keys into a single table (defect) which all point to primary key in user table. It is like: defect (.....,assigned_to,created_by,updated_by,closed_by...) If I want to get information about the defect I can make six joins. Do we have any better way to do it? Another one is I have a states table which can store one of the user-defined set of values. I have defect table and task table and I want both of

How to define a one to one self reference using Entity Framework Code First

一个人想着一个人 提交于 2019-12-22 08:51:10
问题 I want to implement versioning on my entity Stuff . Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity framework 6, code first. I tried with the following model and modelbuilder statement (and many variations). public class Stuff { public int StuffId { get; set; } [ForeignKey("NextVersion")] public int? NextVersionId { get; set; } [InverseProperty(

RestKit: Creating stubs for foreign key relationships

烂漫一生 提交于 2019-12-22 08:13:04
问题 I am struggling to map the foreign key relationships returned by my JSON API with RestKit. Specifically, I use Loopback to generate an API with Entities like Team and User . There are two Endpoints by default that return the following JSON: /Teams/ [ { "title": "Team Title", "id": 1, } ] /Users/ [ { "name": "Alice", "id": 1, "teamId": 1, }, { "name": "Bob", "id": 2, "teamId": 1, }, ... ] Now this is a pretty simple API, right? It should be easy to map with RestKit, but even after reading all

MySQL table with only a varchar as a foreign key

非 Y 不嫁゛ 提交于 2019-12-22 07:58:30
问题 I have a table with a single unique VARCHAR(512) field. I want to have another table hold a foreign key reference to this first table. Both tables use InnoDB. If I add a VARCHAR(512) key to the second table and add a foreign key constraint on it will the 512 bytes long data be held twice? If so, is there a way to hold only a reference to the index and not to the varchar itself? In short, my question is, in InnoDB is there an efficient way to hold foreign keys to long VARCHAR fields? Thank you

One to One relationship in MySQL

瘦欲@ 提交于 2019-12-22 07:36:28
问题 I'm trying to make a one to one relationship in a MySQL DB. I'm using the InnoDB engine and the basic table looks like this: CREATE TABLE `foo` ( `fooID` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` TEXT NOT NULL ) CREATE TABLE `bar` ( `barName` VARCHAR(100) NOT NULL, `fooID` INT(11) NOT NULL PRIMARY KEY, CONSTRAINT `contact` FOREIGN KEY (`fooID`) REFERENCES `foo`(`fooID`) ) Now once I have set up these I alter the foo table so that the fooID also becomes a foreign key to the fooID in