foreign-keys

MySQL + PHP: fetching data using foreign keys

一曲冷凌霜 提交于 2019-12-01 06:01:25
问题 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=

SQL Server 2008 - Multiple Cascading FK's - Do i need a trigger?

≯℡__Kan透↙ 提交于 2019-12-01 05:48:26
I have a 1..* relationship between User and Post . (one user has many posts) Post has a FK called "UserId", which maps to the "UserId" field on User table. I tried to set this FK as Cascade UPDATE/DELETE, but i get this error: 'Users' table saved successfully 'Posts' table - Unable to create relationship 'FK_Posts_Users'. Introducing FOREIGN KEY constraint 'FK_Posts_Users' on table 'Posts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors. I have a table

Adding foreign key of type char in mysql

混江龙づ霸主 提交于 2019-12-01 05:32:05
问题 i got a problem adding a foreign key in mysql (using phpmyadmin). ALTER TABLE `production_x_country` ADD FOREIGN KEY (`country`) REFERENCES `pmdb_0.3.12`.`countries`(`iso_3166_1`) ON DELETE CASCADE ON UPDATE CASCADE; #1215 - Cannot add foreign key constraint based on some research and tests i've come to the conclusion that CHAR (that production_x_country . country field) is no valid foreign key field type - though i did not find any hint to that assumption in the mysql docs. if i change the

django - “Incorrect type. Expected pk value, received str” error

谁都会走 提交于 2019-12-01 05:31:02
I my django-rest-framework I have the following models: Basically every ride has one final destination and can have multiple middle destinations. models.py: class Destination(models.Model): name=models.CharField(max_length=30) class Ride(models.Model): driver = models.ForeignKey('auth.User', related_name='rides_as_driver') destination=models.ForeignKey(Destination, related_name='rides_as_final_destination') leaving_time=models.TimeField() num_of_spots=models.IntegerField() passengers=models.ManyToManyField('auth.User', related_name="rides_as_passenger") mid_destinations=models.ManyToManyField

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

放肆的年华 提交于 2019-12-01 05:29:00
问题 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

Entity Framework Is it possible to add an ASSOCIATION between Primary Keys and a Foreign Key

我的梦境 提交于 2019-12-01 05:22:22
I've got the following entities on my EDMX :- These two entites were generated by Update Model From Database . Now, notice how my country has the following primary key :- Name & IsoCode this is because each country is UNIQUE in the system by Name and IsoCode. Now, with my States ... it's similar. Primary Key is :- Name & CountryId Each state is unique by name and per country. Now, the Foreign Key for States is a CountryId. This is the sql :- ALTER TABLE [dbo].[States] WITH CHECK ADD CONSTRAINT [FK_States_Countries] FOREIGN KEY([CountryId]) REFERENCES [dbo].[Countries] ([CountryId]) ON UPDATE

SQL one-to-many

大憨熊 提交于 2019-12-01 05:03:26
问题 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:

on cascade delete on a table with two FK to the same table [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-01 04:27:38
问题 This question already has an answer here : MS SQL “ON DELETE CASCADE” multiple foreign keys pointing to the same table? (1 answer) Closed 6 years ago . I have a relation called Friends with the following columns, User1ID User2ID Since User1ID and User2ID are a set of primary keys in the relation. They are also foreign keys referencing to the table Users. Now i want to add an ON CASCADE DELETE , such that when a user from table Users is deleted then the corresponding row from table Friends is

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

荒凉一梦 提交于 2019-12-01 04:24:21
问题 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

django - “Incorrect type. Expected pk value, received str” error

左心房为你撑大大i 提交于 2019-12-01 04:12:52
问题 I my django-rest-framework I have the following models: Basically every ride has one final destination and can have multiple middle destinations. models.py: class Destination(models.Model): name=models.CharField(max_length=30) class Ride(models.Model): driver = models.ForeignKey('auth.User', related_name='rides_as_driver') destination=models.ForeignKey(Destination, related_name='rides_as_final_destination') leaving_time=models.TimeField() num_of_spots=models.IntegerField() passengers=models