foreign-key-relationship

Create table fails with Foreign Key Constraint is incorrectly Formed

点点圈 提交于 2019-12-01 03:26:13
问题 Topic MariaDB InnoDB Foreign Key Issue Want to start off by saying I'm new to InnoDB and spent all day reading posts yesterday I've tried multiple things along the way to get me where I am now so am I hosed or is there a way out of this dark forest. I have a table that is central to a number of tables in my data model. So something along these lines: create table users (id int not null auto_increment , username varchar(255) NOT NULL , password varchar(255) NOT NULL , active int NOT NULL ,

How to add an EF6 Association to a Candidate Key / Unique Key which is not the Primary Key?

此生再无相见时 提交于 2019-12-01 03:22:16
Using Schema First , I have a database structure, as so ExternalDataItems --- edataitem_id PK -- surrogate auto-increment - NOT for FK relation here datahash UX -- Candidate Key / Unique Index (binary(20)) ExternalMaps --- emap_id PK ext_datahash FK on ExternalDataItems.datahash - NOT referencing the surrogate PK and after generating the SSDL/CSDL 1 has this <Association Name="FK_ExtMaps_ExtDataItems"> <End Multiplicity="1" Role="ExternalDataItems" Type="Store.ExternalDataItems" /> <End Multiplicity="*" Role="ExternalMaps" Type="Store.ExternalMaps" /> <ReferentialConstraint> <!-- error on this

Laravel foreign key onDelete('cascade') not working

半城伤御伤魂 提交于 2019-11-30 20:05:42
I have a many-to-many relationship between User & Role, with a role_user table. My migrations are setup as so (simplified): users table: public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('email')->unique(); }); } roles table: public function up() { Schema::create('roles', function(Blueprint $table) { $table->increments('id'); $table->string('name'); }); } role_user table: public function up() { Schema::create('role_user', function(Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table-

Rails multiple associations between two models

微笑、不失礼 提交于 2019-11-30 19:40:25
I have Flight, Person, and Glider models in a Rails 3 app. I've defined custom relationships because I need more than one foreign key referencing a Person from the flights table. Associations work but ONE-WAY only. class Flight < ActiveRecord::Base belongs_to :pilot, :class_name => "Person" belongs_to :instructor, :class_name => "Person" belongs_to :towplane_pilot, :class_name => "Person" belongs_to :airplane_instructor, :class_name => "Person" belongs_to :glider belongs_to :rep_glider, :class_name => "Glider" belongs_to :departure_airfield, :class_name => "Airfield" belongs_to :arrival

“Invalid Index n for this SqlParameterCollection with Count=n” OR “foreign key cannot be null”

て烟熏妆下的殇ゞ 提交于 2019-11-30 16:57:56
I have been successfully using NHibernate for quite some time now and have been able to solve a lot of pitfalls with an application that I developed with it and that is running in production. The recent hurdle really has me scratching my head, though. Recently I had to expand the class library with some new classes that are nested as children to some already existing classes. I just copied the same model for aggregate mapping that I already was successfully using, but this time it does not work. Now when I use the following in the parent mapping file: <bag name="SeaInfoItems" table="EDIImport

Need to create a foreign key when creating a table on Rails?

落爺英雄遲暮 提交于 2019-11-30 13:27:23
i'm starting now on Rails, i looked in the forum, but i didn't find anything that could solve my problem. Here it goes, I have a Category table, and it has only name for a column (there is no repetition in categories) so i would like name to be the primary key, then i have a Product table that has name, main_photo, description and i would like to say that a product only has a category, do i need to add a column named category as a foreign key in products? A Category is suposed to have many products. Then in category models how do i say that name is the primary Key, and how can i do the

Whats the difference between a OneToOne, ManyToMany, and a ForeignKey Field in Django?

余生长醉 提交于 2019-11-30 10:05:54
问题 I'm having a little difficulty getting my head around relationships in Django models. Could someone explain what the difference is between a OneToOne, ManyToMany and ForeignKey? 回答1: Well, there's essentially two questions here: What is the difference (in general) between one to one, many to many, and foreign key relations What are their differences specific to Django. Both of these questions are quite easily answered through a simple Google search, but as I cannot find an exact dupe of this

SQLAlchemy: Relation table with composite primary key

大憨熊 提交于 2019-11-30 09:13:19
I have a set of tables that look like: workflows = Table('workflows', Base.metadata, Column('id', Integer, primary_key=True), ) actions = Table('actions', Base.metadata, Column('name', String, primary_key=True), Column('workflow_id', Integer, ForeignKey(workflows.c.id), primary_key=True), ) action_dependencies = Table('action_dependencies', Base.metadata, Column('workflow_id', Integer, ForeignKey(workflows.c.id), primary_key=True), Column('parent_action', String, ForeignKey(actions.c.name), primary_key=True), Column('child_action', String, ForeignKey(actions.c.name), primary_key=True), ) My

Can SQLAlchemy automatically create relationships from a database schema?

我的梦境 提交于 2019-11-30 09:02:40
Starting from an existing (SQLite) database with foreign keys, can SQLAlchemy automatically build relationships ? SQLAlchemy classes are automatically created via __table_args__ = {'autoload': True} . The goal would be to easily access data from related tables without having to add all the relationships one by one by hand (i.e. without using sqlalchemy.orm.relationship() and sqlalchemy.orm.backref ). vvladymyrov [Update] As of SQLAlchemy 0.9.1 there is Automap extension for doing that. For SQLAlchemy < 0.9.0 it is possible to use sqlalchemy reflection. SQLAlchemy reflection loads foreign

foreign key constraint ON DELETE CASCADE not working in sqlite database on android

末鹿安然 提交于 2019-11-30 08:14:01
问题 I have "days" table created as follows "create table days(" + "day_id integer primary key autoincrement, " + "conference_id integer , " + "day_date text, " + "day_start_time text, " + "day_end_time text, " + "day_summary text, " + "day_description text)"; and i have tracks table created as follows CREATE_TABLE_TRACK = "create table track(" + "track_id integer primary key autoincrement," + "day_id integer,"+ "track_name text," + "track_description text," + " FOREIGN KEY(day_id) REFERENCES days