foreign-keys

Defining a Foreign key constraint in H2 Databases

我的未来我决定 提交于 2019-12-04 23:50:51
I am new in coding so I made a tables in SQL server and it worked, so i used the same command in H2 and it said I have a syntax problems with the second table, someone can help? CREATE TABLE TOURISTINFO( TOURISTINFO_ID INT PRIMARY KEY, NAME VARCHAR(25) NOT NULL, NATIONALITY VARCHAR(15) NOT NULL ) CREATE TABLE PLANETICKETS( DESTINATION VARCHAR(10) NOT NULL, TICKETPRICE NUMERIC(8,2) NOT NULL, TOURISTINFO_ID INT FOREIGN KEY REFERENCES TOURISTINFO ) The error is Syntax error in SQL statement "CREATE TABLE PLANETICKETS( DESTINATION VARCHAR(10) NOT NULL, TICKETPRICE NUMERIC(8,2) NOT NULL,

How to ensure data integrity when using Table Per Subclass?

痞子三分冷 提交于 2019-12-04 23:13:10
问题 I am using the table per subclass strategy in Grails by setting the tablePerHierarchy property of the static mapping field in my superclass to false. This way, Grails creates one table for my superclass and one additional table for each of my subclasses. However, while the superclass and subclass records share the same ID (primary key), there are no foreign key constraints to keep them consistent, i.e. it is possible to delete the superclass record, leaving the subclass record in an invalid

Stackoverflows Tags system, How To

↘锁芯ラ 提交于 2019-12-04 22:36:48
OK so now I can understand that SO's search system is primarily based around tags, the tag system they use is a very good one at that but what I want to do is replicate it for my own projects. Now I can understand how to use foreign keys and such, but I'm not exactly sure how it's been developed here, do they use 3 tables or 2 etc. How have they developed it, can you show me some MySql examples? OMG Ponies SO considers questions and answers to be the same thing - a Post . Here's a stripped down MySQL equivalent table: DROP TABLE IF EXISTS `example`.`post`; CREATE TABLE `example`.`post` (

What's the right HTTP status code for a response when I can't perform a DELETE due to a FK constrain?

我的未来我决定 提交于 2019-12-04 22:35:23
What would be the right response I should give to the users when they try to DELETE an entity on a datasource sitting behind a rest/odata api, and the operation cannot be performed due to a foreign key constrain? Is it a bad request? A not acceptable? A server-side error (>=500)? Just found this website that says that '409 Conflict' should be used when 'the request could not be completed due to a conflict with the current state of the resource' and 'where it is expected that the user might be able to resolve the conflict and resubmit the request', then it gives an example when 'cascade-delete

How can I load HABTM-with-foreign-key relationships in my fixtures?

一曲冷凌霜 提交于 2019-12-04 22:33:26
问题 I have the following two models: School and User, and a HABTM relationship between them, with a join table. In this join table, the foreign key refering to the User table is not called user_id but student_id . class School < ActiveRecord::Base has_and_belongs_to_many :students, :class_name => "User", :join_table => "schools_students", :foreign_key => "student_id" end class User < ActiveRecord::Base has_and_belongs_to_many :studying_schools, :class_name => "School", :join_table => "schools

Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed

跟風遠走 提交于 2019-12-04 22:22:18
问题 I'm working on adding Django 2.0 support to the django-pagetree library. During automated testing, using an sqlite in-memory database, I'm getting a bunch of errors like this: File "/home/nnyby/src/django-pagetree/pagetree/tests/test_models.py", line 638, in setUp 'children': [], File "/home/nnyby/src/django-pagetree/pagetree/models.py", line 586, in add_child_section_from_dict ... File "/home/nnyby/src/django-pagetree/venv/lib/python3.5/site-packages/django/db/backends/base/base.py", line

Why did Rails 5 changed “index” to “foreign key”?

孤人 提交于 2019-12-04 22:09:42
问题 If you had this in Rails 4: t.references :event, index: true Now you could use foreign_key instead of index in Rails 5. I don't quite understand WHY they decided to do this, since the functionality remains the same, what you're adding is an INDEX, not a FOREIGN KEY to that column. 回答1: In Rails 5 - when we reference a model, index on the foreign_key is automatically created. Migration API has changed in Rails 5 - Rails 5 has changed migration API because of which even though null: false

Using PostgreSQL, why doesn't Hibernate/JPA create cascade constraints?

走远了吗. 提交于 2019-12-04 21:06:30
问题 I have an entity Bar : @OneToMany(cascade = CascadeType.ALL, mappedBy = "bar") private Set<Foo> fooSet; And an entity Foo : @ManyToOne(optional = false) @JoinColumn(name = "bar_id") private Bar bar; Hibernate creates the foreign key constraint on foo.bar -> bar.id but it doesnt specify ON DELETE CASCADE . Why not? And is there any ways to achieve it? Alternatively I can add the ON DELETE CASCADE manually in the DB (and disable DDL generation), is this a good practice? And also, do I have to

Entity Framework Code first - FOREIGN KEY constraint problem

孤人 提交于 2019-12-04 19:58:39
问题 I'm new to EF code first principal and currently with no clue what to do.. I have 2 POCO classes.. public class Problem { public int ProblemID { get; set; } public int UserID { get; set; } public int CategoryID { get; set; } public int RatingID { get; set; } public string Title { get; set; } public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public int State { get; set; } public DateTime CreatedOn { get; set; } public virtual

Comment system design

…衆ロ難τιáo~ 提交于 2019-12-04 19:50:52
Here is my current comment system design: I'm developing it for a website that has lots of areas, blogs, tutorials, manuals etc etc. As supposed to developing a separate comment table for each ( tblBlogComments , tblTutorialComments ) etc etc, I'm trying to go for a one structure fits all approach. This way, I can turn the comment system into a web control, and just drop it on any page that I want comments for. It means I only have one set of rules, one set of code files to maintain. The only problem is, is coming up with a 'nice' way to determine which section (blog/tutorial/manual) belongs