foreign-keys

How to relate table with one of many others?

蹲街弑〆低调 提交于 2019-12-13 20:56:59
问题 I am little confused about my db design. I have orders table that may have records from one of many others. So is it OK to relate each tables with 1:1 to orders . Please look at orders domains and hostings table relations. My orders table rows has either a domain or hosting regarding to its orders_type value. 回答1: Are you asking if the orders should have 1:1 relationship with domains and another 1:1 relationship with hostings? If you are, the answer is no. Your hosting table has an orders_id

CakePHP hasOne-belongsTo relationship, how to look up and insert foreign key from user input?

我与影子孤独终老i 提交于 2019-12-13 20:34:57
问题 I have two tables: Property (..., postcode_id, ...) Postcode (id, postcode, latitude, longitude) The relationship: class Property extends AppModel { public $belongsTo = array( 'Postcode' => array( 'className' => 'Postcode' ) ); class Postcode extends AppModel { public $hasMany = array( 'Property' => array( 'className' => 'Property' ) ); What I'd like to happen: Enter a postcode in the Property add form. Check entered postcode is in the Postcode table. If not, so some logic (possibly add it,

Django, use of ForeignKey's value within model

扶醉桌前 提交于 2019-12-13 20:31:53
问题 I would like to make a system, which is photos belong to projects. I also enabled that I can upload a zipfile directly for a project and it will unzip and register the photos to the specified project. However, I am having troubles while defining the Photo class. I need to get the value of Project.file_zip.path with the current instance for defining img field's upload_to attribute. However, when I tried like below, it returns with AttributeError: 'ForeignKey' object has no attribute 'file_path

NHibernate one-to-many foreign key is NULL

烈酒焚心 提交于 2019-12-13 20:22:24
问题 I have a problem with NHibernate. What i am trying to to is very simple: I have two Classes. UserTicket and UserData. A UsertTicket has some UserData and a UserData belongs to one UserTicket: public class UserData{ public virtual int Id { get; set; } public virtual String PDF_Path { get; set; } } public class UserTicket { public virtual int Ticketnr { get; set; } public virtual IList<UserData> UserData { get; set; } } And here the mappig xml: <class name="UserTicket" table="UserTicket"> <id

When renaming column in Users table getting: SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE “users”

喜欢而已 提交于 2019-12-13 19:07:01
问题 I am working on a Rails app with Sqlite and have a users table associated with several other tables. When trying to rename a column in Users, I'm getting the subject error when running rails db:migrate. I see a lot of posts here with similar issues, but none has worked. Specifically, the common remedy seems to be to use "dependent: :destroy" on all has_many and has_one associations. I am doing this but am still getting the error. What am I doing wrong? Below is my code: class User <

Derby foreign key constraint

风流意气都作罢 提交于 2019-12-13 19:01:20
问题 What's the problem with this statement that gives me the following exception? s.addBatch("CREATE TABLE category ( id SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY \n" + "\t(START WITH 0, INCREMENT BY 1), title VARCHAR(100))\n" ); s.addBatch("CREATE TABLE task (id SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY \n" + "\t(START WITH 0, INCREMENT BY 1), title VARCHAR(100), cat_id INT, visible BOOLEAN, " + "deprecated BOOLEAN" + "CONSTRAINT fk_cat_id FOREIGN KEY (cat_id)\n" + "\tREFERENCES

Using a trigger to implement a foreign key check constraint

拜拜、爱过 提交于 2019-12-13 18:41:41
问题 I'm trying to implement this constraint into my database: (In the table Race) CONSTRAINT (Date <= Meeting.EndDate) Essentially the column in the Race Table needs to be Less than the EndDate column in the Meeting table. Pretty sure I need to use a trigger to implement a foreign key however, I'm not that sure how I would go about implementing one. So Far, All I have is: CREATE OR REPLACE TRIGGER RaceDateCheck AFTER UPDATE OF Race ON StartDateCheck BEGIN INSERT INTO Race (MeetingEndDate) SELECT

how to use foreign-keys with hsql create table?

假装没事ソ 提交于 2019-12-13 18:06:07
问题 could someone explain me how to use foreign keys in hsql? I would like it in an create table, but working alter table is also ok. I am working without tools, just in eclipse whats wrong with the hsql code? CREATE TABLE user( t_id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY, name VARCHAR(30), lastname VARCHAR(30), email VARCHAR(30), --FOREIGN KEY (b_id) REFERENCES bookingnumber(b_id) ); CREATE TABLE bookingnumber ( b_id INTEGER PRIMARY KEY ); ALTER TABLE

Since EF doesn't support DELETE SET NULL, Can I run an SQL command outside EF to do it?

≯℡__Kan透↙ 提交于 2019-12-13 16:26:32
问题 I know that you set a nullable key in your entity if you want that FK to be nullable: class ChildEntity { // Other properties not shown for brevity public int? ParentId { get; set; } public virtual ParentEntity Parent; { get; set; } } This will result in a nullable FK. It was suggested here that we should also set the optional relationship in Fluent: modelBuilder.Entity<ChildEntity>() .HasOptional(c => c.Parent) .WithMany() .HasForeignKey(c => c.ParentId); but this still doesn't set delete

Create foreign key without checking existing data

℡╲_俬逩灬. 提交于 2019-12-13 16:22:31
问题 This is a 2 part question. Question 1: I am trying to create a foreign key on a table where I need to turn off the "Check Existing Data on Creation or Re-Enabling". I know theres an option visually but I'm looking for a way to do it programmatically. Is there anyway to do this? Question 2: I have a code table and two tables A and B that need to reference that code table. I want to have these both referenced from a relationship table but I want to able to use the same column. Can I have 2