unique-key

How to get EF6 to honor Unique Constraint (on FK) in Association/Relationship multiplicity?

为君一笑 提交于 2019-11-29 03:30:19
2019 Update / TLDR; switch to Entity Framework Core (or whatever else) While missing some "Features", EF Core properly honors Alternate Keys (aka Unique Constraints) in addition to Primary Keys and thus does a much better job of honoring Relational Algebra. YMMV otherwise; at least it supports many more SQL schemes correctly. This support added was in the (very outdated) EF Core 1.0 release .. a bit disappointing that the original EF never had this design(ed!) flaw addressed. This may be related to my other question - which seems to be that either: Entity Framework is a terrible Relational

Primary key and unique key in django

拟墨画扇 提交于 2019-11-28 21:25:36
I had a custom primary key that need to be set up on a particular data in a model. This was not enough, as an attempt to insert a duplicate number succeeded. So now when i replace primary_key=True to unique=True it works properly and rejects duplicate numbers!!. But according this document ( which uses fields ). primary_key=True implies null=False and unique=True. Which makes me confused as in why does it accept the value in the first place with having an inbuilt unique=True ? Thank you. Updated statement: personName = models.CharField(primary_key=True,max_length=20) mipadi Use an AutoField

MySQL - Make a pair of values unique

爷,独闯天下 提交于 2019-11-28 19:07:30
I have a table with two int values that are IDs. On their own these IDs can show up any number of times in the table, but together they should only ever appear once. Is there a way to make a pair of values unique and still allow the individual values to show up multiple times? As a follow up, if this is possible can the pair of values be used as a key? I currently have a 3rd column for a unique auto increment value for my key. Raphaël Althaus It's called a composite key. If you want to change your actual PK to a composite one, use Alter table <your table> drop PRIMARY KEY; Alter table <your

Is the Sql Server Unique Key also an Index?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:41:57
I've got a column in a table (eg. UserName) which I want to make sure is unique. So I create a unique key for that column and call it IX_Users_UserName. Now, if I do lots of searching for users based on their username I want to make sure there is an index for that field. Do I need to create a separate index, or is the unique key also considered an index, just like the primary key is a clustered unique key? Unique Key: Unique Key enforces uniqueness of the column on which they are defined. Unique Key creates a non-clustered index on the column. Unique Key allows only one NULL Value. Alter table

#1062 - Duplicate entry '' for key 'unique_id' When Trying to add UNIQUE KEY (MySQL)

天涯浪子 提交于 2019-11-28 05:20:44
I've got an error on MySQL while trying to add a UNIQUE KEY. Here's what I'm trying to do. I've got a column called 'unique_id' which is VARCHAR(100). There are no indexes defined on the table. I'm getting this error: #1062 - Duplicate entry '' for key 'unique_id' When I try to add a UNIQUE key. Here is a screenshot of how I'm setting it up in phpMyAdmin: Here is the MySQL query that's generate by phpMyAdmin: ALTER TABLE `wind_archive` ADD `unique_id` VARCHAR( 100 ) NOT NULL FIRST , ADD UNIQUE ( `unique_id` ) I've had this problem in the past and never resolved it so I just rebuilt the table

make text column as unique key

流过昼夜 提交于 2019-11-28 00:39:08
i want to make a table in MySQL server with mediumtext column as UNIQUE KEY CREATE TABLE `parts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` mediumtext NOT NULL, `display_status` int(11) NOT NULL, UNIQUE KEY `name` (`name`), PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; but this made an error BLOB/TEXT column 'name' used in key specification without a key length when I change the type of `name` to varchar .. it works! can you tell if i can to make text column as UNIQUE KEY Basically you can not use Text column as UNIQUE key. Because practically such a big column will not be

MySQL Question - Unique Key Not functioning correctly, or am I misunderstanding?

北城余情 提交于 2019-11-27 22:12:00
问题 I'm trying to create a relation where any of four different parts may be included, but any collection of the same parts should be handled as unique. Example: An assignment must have an assigned company, may optionally have an assigned location, workgroup and program. An assignment may not have a workgroup without a location. Let's assume we have companies A, B, C; locations X, Y, Z; workgroups I, J, K and programs 1, 2, 3. So valid relations could include A - X - I - 1 A - Z - 2 B - Y C C - 3

Solr Composite Unique key from existing fields in schema

大兔子大兔子 提交于 2019-11-27 21:30:19
I have an index named LocationIndex in solr with fields as follows: <fields> <field name="solr_id" type="string" stored="true" required="true" indexed="true"/> <field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/> // and some more fields </fields> <uniqueKey>solr_id</uniqueKey> But now I want to change schema so that unique key must be composite of two already present fields solr_id and solr_ver ... something as follows: <fields> <field name="solr_id" type="string" stored="true" required="true" indexed="true"/> <field name="solr_ver" type="string"

Oracle unique constraint and unique index

你。 提交于 2019-11-27 19:17:30
Could someone clarify what is the purpose of having unique index without unique constraint (Oracle)? For example, create table test22(id int, id1 int, tmp varchar(20)); create unique index idx_test22 on test22(id); insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // ok insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // fails, ORA-00001: unique // constraint (TEST.IDX_TEST22) violated So far it looks like there is a constraint. But create table test33(id int not null primary key, test22_id int not null, foreign key(test22_id) references test22(id) ); also fails with "ORA-02270: no

How can I catch UniqueKey Violation exceptions with EF6 and SQL Server?

老子叫甜甜 提交于 2019-11-27 18:58:10
One of my tables have a unique key and when I try to insert a duplicate record it throws an exception as expected. But I need to distinguish unique key exceptions from others, so that I can customize the error message for unique key constraint violations. All the solutions I've found online suggests to cast ex.InnerException to System.Data.SqlClient.SqlException and check the if Number property is equal to 2601 or 2627 as follows: try { _context.SaveChanges(); } catch (Exception ex) { var sqlException = ex.InnerException as System.Data.SqlClient.SqlException; if (sqlException.Number == 2601 ||