foreign-keys

I get an error in PostgreSql: number of referencing and referenced columns for foreign key disagree

你说的曾经没有我的故事 提交于 2020-08-08 02:02:31
问题 I'm creating a table, but I get this error: number of referencing and referenced columns for foreign key disagree. I don't know how to solve it. I think that it may be a problem with declaring 3 foreign keys, but, I'm not sure about it. What is the problem? Create table Trasllat ( Data Date, Codi_Empleat Integer, Nom_agencia Varchar(30), Data_fi Date, Primary key (Data, Codi_Empleat), Foreign key (Data) references Data on delete cascade, Foreign key (Codi_empleat) references Empleat on delete

I get an error in PostgreSql: number of referencing and referenced columns for foreign key disagree

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-08 01:56:04
问题 I'm creating a table, but I get this error: number of referencing and referenced columns for foreign key disagree. I don't know how to solve it. I think that it may be a problem with declaring 3 foreign keys, but, I'm not sure about it. What is the problem? Create table Trasllat ( Data Date, Codi_Empleat Integer, Nom_agencia Varchar(30), Data_fi Date, Primary key (Data, Codi_Empleat), Foreign key (Data) references Data on delete cascade, Foreign key (Codi_empleat) references Empleat on delete

SQLAlchemy ORM not working with composite foreign keys

杀马特。学长 韩版系。学妹 提交于 2020-07-16 06:41:08
问题 I'm trying to build an example with several related models, like the following. We have a model B with a 1:n relation with a model C; then we have a model A with a n:1 relation with B and a n:1 relation with C. (C has a 2-columns primary key) I tried this code: class C(db.Model): __tablename__ = 'C' key1 = Column(Integer, primary_key=True) key2 = Column(Integer, primary_key=True) attr1 = Column(Date) attr2 = Column(Boolean) related_b = Column(Integer, ForeignKey('B.spam')) class B(db.Model):

Number duplicates sequentially in Pandas DataFrame

前提是你 提交于 2020-07-08 18:58:13
问题 I have a Pandas DataFrame that has a column that is basically a foreign key, as below: Index | f_key | values 0 | 1 | red 1 | 2 | blue 2 | 1 | green 3 | 2 | yellow 4 | 3 | orange 5 | 1 | violet What I would like is to add a column that labels the repeated foreign keys sequentially, as in "dup_number" below: Index | dup_number | f_key | values 0 | 1 | 1 | red 1 | 1 | 2 | blue 2 | 2 | 1 | green 3 | 2 | 2 | yellow 4 | 1 | 3 | orange 5 | 3 | 1 | violet The rows can be reordered if needed, I just

Entity Framework Core: How to solve Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-06 08:44:28
问题 I'm using Entity Framework Core with Code First approach but recieve following error when updating the database: Introducing FOREIGN KEY constraint 'FK_AnEventUsers_Users_UserId' on table 'AnEventUsers' 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 or index. See previous errors. My entities are these: public class AnEvent { public int AnEventId { get; set; } public DateTime

How to list tables in their dependency order (based on foreign keys)?

三世轮回 提交于 2020-06-24 13:53:07
问题 This question was originally asked by @PrateekGupta Background @PrateekGupta wanted to perform bulk insert operation on multiple tables. The tables have foreign key relationships between themselves. If an INSERT operation is done on a table with a foreign key before the referenced table is being inserted to, the operation might fail due to violation of the foreign key. Requirement Produce a list of tables within a database ordered according to their dependencies. Tables with no dependencies

Is it possible to have more than one foreign key in a normalised database schema?

徘徊边缘 提交于 2020-06-17 14:10:30
问题 Address ( addressID , houseNumber, postcode, roadName, city, county) Reservation ( reservationID , roomNo, leadGuestID, guest2ID, guest3ID , arrivalDate, departureDate, addressID , amountOutstanding) Guest ( guestID , firstName, lastName, adultFlag, telephoneNo, addressID , emailAddress) Room ( roomNo , roomTypeName ) RoomType ( roomTypeName , floor, basePrice, extraAdultPrice, extraChildPrice) The above schema is supposed to be normalised 4NF. But I cannot see how leadGuestID, guest2ID &