foreign-keys

Dealing with import of foreignKeys in django-import-export

半城伤御伤魂 提交于 2019-11-27 22:45:24
问题 I don't understand how django-import-export module deals with ForeignKeys. Here is a simple exemple : models.py class TFamilies(models.Model): id_fam = models.AutoField(primary_key=True, unique=True) name_fam = models.CharField(max_length=1024, blank=True,verbose_name='Famille') class TGenus(models.Model): id_genus = models.AutoField(primary_key=True, unique=True) name_genus = models.CharField(max_length=1024,verbose_name='nom de genre') id_fam = models.ForeignKey(TFamilies, null=True, db

Can I have a foreign key referencing a column in a view in SQL Server?

青春壹個敷衍的年華 提交于 2019-11-27 21:45:37
In SQL Server 2008 and given TableA(A_ID, A_Data) TableB(B_ID, B_Data) ViewC(A_or_B_ID, A_or_B_Data) is it possible to define TableZ(A_or_B_ID, Z_Data) such that Z.A_or_B_ID column is constrained to the values found in ViewC ? Can this be done with a foreign key against the view? You can't reference a view in a foreign key. In older SQL Server editions foreign keys were possible only through triggers. You can mimic a custom foreign key by creating an Insert trigger which checks whether the inserted value appears in one of the relevant tables as well. If you really need A_or_B_ID in TableZ, you

“General error: 1005 Can't create table” Using Laravel Schema Build and Foreign Keys

▼魔方 西西 提交于 2019-11-27 21:03:59
Essentially, I am having the same issue as this guy, minus the table prefix. Because I have no table prefix, his fix does not work. http://forums.laravel.com/viewtopic.php?id=972 I am trying to build a table using Laravel's Schema Builder like this: Schema::create('lessons', function($table) { $table->increments('id'); $table->string('title')->nullable(); $table->string('summary')->nullable(); $table->timestamps(); }); Schema::create('tutorials', function($table) { $table->increments('id'); $table->integer('author'); $table->integer('lesson'); $table->string('title')->nullable(); $table-

Can a foreign key act as a primary key?

故事扮演 提交于 2019-11-27 20:38:04
I'm currently designing a database structure for our team's project. I have this very question in mind currently: Is it possible to have a foreign key act as a primary key on another table? Here are some of the tables of our system's database design: user_accounts students guidance_counselors What I wanted to happen is that the user_accounts table should contain the IDs (supposedly the login credential to the system) and passwords of both the student users and guidance counselor users. In short, the primary keys of both the students and guidance_counselors table are also the foreign key from

Can you automatically create a mysqldump file that doesn't enforce foreign key constraints?

你。 提交于 2019-11-27 20:22:31
When I run a mysqldump command on my database and then try to import it, it fails as it attempts to create the tables alphabetically, even though they may have a foreign key that references a table later in the file. There doesn't appear to be anything in the documentation and I've found answers like this that say to update the file after it's created to include: set FOREIGN_KEY_CHECKS = 0; ...original mysqldump file contents... set FOREIGN_KEY_CHECKS = 1; Is there no way to automatically set those lines or export the tables in the necessary order (without having to manually specify all table

Should Hibernate be able to handle overlapping foreign keys?

牧云@^-^@ 提交于 2019-11-27 20:16:26
I have a table that has two foreign keys to two different tables with both foreign keys sharing one column : CREATE TABLE ZipAreas ( country_code CHAR(2) NOT NULL, zip_code VARCHAR(10) NOT NULL, state_code VARCHAR(5) NOT NULL, city_name VARCHAR(100) NOT NULL, PRIMARY KEY (country_code, zip_code, state_code, city_name), FOREIGN KEY (country_code, zip_code) REFERENCES Zips (country_code, code), FOREIGN KEY (country_code, state_code, city_name) REFERENCES Cities (country_code, state_code, name) ) As you can see, there are two FKs sharing country_code (coincidentally referencing the same column at

Why do I need to use foreign key if I can use WHERE?

我的梦境 提交于 2019-11-27 20:11:53
问题 A beginners' question about foreign key in MySQL. In w3school it says, A FOREIGN KEY in one table points to a PRIMARY KEY in another table. And also there is WHERE, WHERE id = page_id So if I can use WHERE for linking the tables, what is the main purpose of having foreign key? 回答1: It's not strictly needed for the query, it's true. It exists for several reasons: As a constraint on the table to stop you inserting something that doesn't point to anything; As a clue for the optimizer; and For

Does Rails need database-level constraints?

故事扮演 提交于 2019-11-27 19:45:32
I have the same problem as in the following post . So I am wondering, why doesn't Rails support generating foreign keys by default? Isn't it necessary? Or are we supposed to do it manually? Database constraints aren't required any more than wearing seat-belts are required in your car. You can drive around all you like and everything will work great until a problem arrives. The seat-belt (constraints) keep you (the data) safe. So it's highly recommended that you create constraints to enforce data-integrity at the database level, because it's highly likely that 1) You will interact with the

can we have a foreign key which is not a primary key in any other table?

ⅰ亾dé卋堺 提交于 2019-11-27 18:59:17
it is written in every book that foreign keys are actually primary key in some other table but can we have a foreign key which is not primary key in any other table Yes - you can have a foreign key that references a unique index in another table. CREATE UNIQUE INDEX UX01_YourTable ON dbo.YourTable(SomeUniqueColumn) ALTER TABLE dbo.YourChildTable ADD CONSTRAINT FK_ChildTable_Table FOREIGN KEY(YourFKColumn) REFERENCES dbo.YourTable(SomeUniqueColumn) By definition a foreign key must reference a candidate key of some table. It doesn't necessarily have to be the primary key. As a matter of detail

MySQL non primary foreign key

梦想与她 提交于 2019-11-27 18:56:44
问题 I'm a bit of a newbie and I can't get my head around primary keys as foreign keys. To me, foreign keys are meant to connect two rows of a table together. Therefore, it would make logical sense to use the, for example, username of the user table as a foreign key in the picture table. This means that the picture in that row belongs to the specified user. However, it appears that general practice favors using meaningless numbers as primary IDs. Furthermore the foreign key must/should refer to