foreign-keys

sequelize foreign key returning as “Null”

你离开我真会死。 提交于 2020-03-05 11:55:12
问题 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')

How do I convert a relational hierarchy to a closure table in MySQL?

ぐ巨炮叔叔 提交于 2020-02-25 05:30:33
问题 I recently started using a closure table, and it was working fine when I had to convert simple parent-child relationships from person to lineage, but now I have to convert grandparent-parent-child and great-grandparent-parent-child relationships, and maybe even longer relationships than that into the closure table. This is the table I need to pull the relationships from: CREATE TABLE `person` ( `person` BIGINT UNSIGNED NOT NULL , `parent` BIGINT UNSIGNED NULL , PRIMARY KEY (`person`) , INDEX

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint Laravel

耗尽温柔 提交于 2020-02-18 05:00:30
问题 Im trying to create a foreign keys using artisan , but this error show up. [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `comments` add constraint `comments_comment_lot_id_foreign` foreign key (`comment_lot_id`) references `lots` (`lot_id` ) on delete cascade) This is my migration: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

MySQL Error 1822: Failed to add foreign key constraint; missing index for contraint BUT index exists

时光总嘲笑我的痴心妄想 提交于 2020-02-14 02:23:41
问题 I am trying to add an foreign key to my flightschedule table but it fails, but I do not really know why. The foreign key should reference the txtAC_tag attribute from the tblAircraft table which is part of the Primary key! So the tblAircraft is indexed (the primary key is a combined key which consists of idAC and txtAC_tag -> could a combined Primary key be the problem?) and the attribute's datatype do match. Here are my table declarations and the foreign key declarations: create table if not

How to update the PRIMARY KEY/FOREIGN KEY in other related tables?

我与影子孤独终老i 提交于 2020-02-07 06:00:06
问题 walls wall_id (P) wall_name wall_views wall_downloads wall_thumbnail_path ( 4, 'wall4', '125', '574', '../.../thumbnail_wall4.jpg' ) types type_id type_name ( '1', 'Desktop' ) ( '2', 'Phone' ) ( '3', 'Tablet' ) wall_types wall_id (P) (F) type_id (P) (F) ( 4, 1 ) Above are the tables I have, what I want to do is automatically get the wall_id = 4 from walls tables and store it in wall_types table, same with the type_id from types table. How can this be done? what is the code (PHP code) or SQL

Bulk Insert DataSet with multiple related tables into SQL Server C#

穿精又带淫゛_ 提交于 2020-02-06 07:40:08
问题 I have a DataSet with multiple tables the source document is an XML file. mydataset.ReadXML(filename); There are multiple tables with multiple relations. I have the database in the SQL created via code - tables, columns and relations. Now I would like to insert the data . (Yes I want everything). EDIT: The SQL tables use Identity Columns autogenerate - because I am not sure the incoming data will never duplicate one of the parameters that I would like to assume is unique. So what methods

Bulk Insert DataSet with multiple related tables into SQL Server C#

不打扰是莪最后的温柔 提交于 2020-02-06 07:39:10
问题 I have a DataSet with multiple tables the source document is an XML file. mydataset.ReadXML(filename); There are multiple tables with multiple relations. I have the database in the SQL created via code - tables, columns and relations. Now I would like to insert the data . (Yes I want everything). EDIT: The SQL tables use Identity Columns autogenerate - because I am not sure the incoming data will never duplicate one of the parameters that I would like to assume is unique. So what methods

Insert Data into a table in php which has a foreign key field

≡放荡痞女 提交于 2020-02-04 02:26:30
问题 I am modifiny an existing project by adding a feedback form to it. I need to store feedback form data into a table call feedback_formtb . I code the sql to create this table. And also there is an already created table call profile_request and I want to take a foreign key from this profile_request table. So I add the request_id field as the foreign key.(I have no permission to edit profile_request table because that part is already developed) I crate a file call feedback_test.php . Now I want

Can a Foreign Key be part of a Composite Primary Key for another table?

假如想象 提交于 2020-02-03 12:25:27
问题 I have two(of many) tables in a music database: Concerts: ArtistID,ConcertID,ConcetName,VenueID ConcertDetails: ConcertDate, ConcertID, Cost The ConcertDetails tables as you see, uses ConcertID which is also in the Concerts table. I combine ConcertDate & ConcertID to make a Composite Primary Key for ConcertDetails. However since this relates to ConcertID from Concerts table it also needs to be a Foreign Key. Is this ok to do? 回答1: Yes, of course. It's common for a subset of a primary key to

Can a Foreign Key be part of a Composite Primary Key for another table?

断了今生、忘了曾经 提交于 2020-02-03 12:24:13
问题 I have two(of many) tables in a music database: Concerts: ArtistID,ConcertID,ConcetName,VenueID ConcertDetails: ConcertDate, ConcertID, Cost The ConcertDetails tables as you see, uses ConcertID which is also in the Concerts table. I combine ConcertDate & ConcertID to make a Composite Primary Key for ConcertDetails. However since this relates to ConcertID from Concerts table it also needs to be a Foreign Key. Is this ok to do? 回答1: Yes, of course. It's common for a subset of a primary key to