foreign-keys

MySQL cascade update failed when foreign key column referenced in composite primary key

耗尽温柔 提交于 2021-01-28 11:44:44
问题 Unlike the similar other questions, I get error #1452 when updating the parent row. Why does it happen? Thank you in advance. Here are the relevant tables: CREATE TABLE IF NOT EXISTS `user` ( `username` VARCHAR(100) NOT NULL, `password` VARCHAR(200) NOT NULL, `name` VARCHAR(100), `surname` VARCHAR(100), `icon` BLOB, PRIMARY KEY (username) ); CREATE TABLE IF NOT EXISTS `document` ( `owner` VARCHAR(100) NOT NULL, `name` VARCHAR(100) NOT NULL, `sharing_link` VARCHAR(200) UNIQUE NOT NULL, PRIMARY

MySQL cascade update failed when foreign key column referenced in composite primary key

依然范特西╮ 提交于 2021-01-28 11:34:26
问题 Unlike the similar other questions, I get error #1452 when updating the parent row. Why does it happen? Thank you in advance. Here are the relevant tables: CREATE TABLE IF NOT EXISTS `user` ( `username` VARCHAR(100) NOT NULL, `password` VARCHAR(200) NOT NULL, `name` VARCHAR(100), `surname` VARCHAR(100), `icon` BLOB, PRIMARY KEY (username) ); CREATE TABLE IF NOT EXISTS `document` ( `owner` VARCHAR(100) NOT NULL, `name` VARCHAR(100) NOT NULL, `sharing_link` VARCHAR(200) UNIQUE NOT NULL, PRIMARY

hbm2ddl - How to avoid that Hibernate is creating Foreign Key constraints?

若如初见. 提交于 2021-01-28 07:44:03
问题 Dear all I am using Hibernate with hbm2ddl. I don't like that for one relationship foreign key constraints get created. Unfortunately I could not achieve it so far. I tried it with Hibernate and JPA annotations, had no luck. Any hints? I am using Hibernate 4.3.1 and mysql 5.6 @Entity class Artikel { ... @OneToMany(fetch=FetchType.LAZY, mappedBy="artikel") @NotFound(action=NotFoundAction.IGNORE) private List<Bild> images; } import javax.persistence.Entity; import javax.persistence.FetchType;

Django foreign key query, why it returns None?

巧了我就是萌 提交于 2021-01-28 05:23:13
问题 When I try to query foreign keys using get(), I always get None values, even though I know they are set to 1 in the DB. Am I missing something here? Should I do something different to get the foreignkey values? Here's what the code looks like: class Car_to_brand( models.Model ): brand_id = models.ForeignKey( Brand, db_column='brand_id' ) ... class Brand( models.Model ): (id is not defined here but it's the primary key) ... print Car_to_brand.__dict__.get( brand_id ) That would give me {brand

Importing CSV with Asian Characters in PHP [closed]

余生长醉 提交于 2021-01-28 05:08:50
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Improve this question I'm trying to import CSVs or Unicode Text with Thai Characters into MySQL. There's no problem with MySQL saving Thai Characters. The problem is, when I use fgetcsv or fgets, I get garbage in exchange for the Thai Characters. Like for example, these characters,

TypeORM why is my relationship column undefined? foreign-key is undefined

强颜欢笑 提交于 2021-01-28 05:03:39
问题 I just use TypeORM and find the relationship column is undefined @Entity({name: 'person'}) export class Person { @PrimaryGeneratedColumn('uuid') id!: string; @OneToOne( () => User) @JoinColumn() user!: User; @Column({ type: "enum", enum: PersonTitle, default: PersonTitle.Blank }) title?: string; @Column({type: 'varchar', default: ''}) first_name!: string; @Column('varchar') last_name!: string; @ManyToOne(() => Organization, org => org.people, { nullable: true}) belong_organization!:

Laravel get data based on foreign key

让人想犯罪 __ 提交于 2021-01-27 17:24:40
问题 So I have 2 tables, TABLE1 and TABLE2. They are linked throug Eloquent: TABLE1 has many TABLE2's, and TABLE2 has one TABLE 1. They are linked with foreign keys as such: in TABLE2 table1_id -> links to -> TABLE1 id. How do I retrieve the entire table data or TABLE 2, + replace table1_id with a column of table1 (let's say by booktitle for example)? Sorry for the abstraction, but this is the best way I can explain it? :D 回答1: The easiest way is to make use of Eloquent's eager loading and fetch

Laravel get data based on foreign key

邮差的信 提交于 2021-01-27 17:21:22
问题 So I have 2 tables, TABLE1 and TABLE2. They are linked throug Eloquent: TABLE1 has many TABLE2's, and TABLE2 has one TABLE 1. They are linked with foreign keys as such: in TABLE2 table1_id -> links to -> TABLE1 id. How do I retrieve the entire table data or TABLE 2, + replace table1_id with a column of table1 (let's say by booktitle for example)? Sorry for the abstraction, but this is the best way I can explain it? :D 回答1: The easiest way is to make use of Eloquent's eager loading and fetch

Inserting new records with one-to-many relationship in sqlalchemy

女生的网名这么多〃 提交于 2021-01-20 14:12:27
问题 I'm following the flask-sqlalchemy tutorial on declaring models regarding one-to-many relationship. The example code is as follows: class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) addresses = db.relationship('Address', backref='person', lazy='dynamic') class Address(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(50)) person_id = db.Column(db.Integer, db.ForeignKey('person.id')) Now I'm wondering how to

Inserting new records with one-to-many relationship in sqlalchemy

一世执手 提交于 2021-01-20 14:12:23
问题 I'm following the flask-sqlalchemy tutorial on declaring models regarding one-to-many relationship. The example code is as follows: class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) addresses = db.relationship('Address', backref='person', lazy='dynamic') class Address(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(50)) person_id = db.Column(db.Integer, db.ForeignKey('person.id')) Now I'm wondering how to