primary-key

Duplicate key value violates unique constraint, CakePHP

半城伤御伤魂 提交于 2019-12-13 07:05:08
问题 I have set my postgres database populated and all constraints applied. I ran cake bake all on all tables and start to test. I got this error: Error: SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "fasciculos_pkey1" DETAIL: Key (id)=(7) already exists. SQL Query: INSERT INTO "xconv2"."fasciculos" ("created", "user_id", "revista_id", "volume", "issue", "svol", "snum", "issuedate", "scheme", "reftype", "cliente_id", "output_packtype", "modified")

How to prevent primary serial primary key from being updated with number not in sequence?

旧时模样 提交于 2019-12-13 06:32:11
问题 CREATE TABLE u_account ( Jid serial primary key, score int4 ); The primary key works fine (updates itself) ok when I update it like this; INSERT INTO u_account ('score') VALUES ('122233344'); However when I insert a value like this; INSERT INTO u_account VALUES ('122233344'); This updates the primary key; I don't want the primary key to accept anything other than the number that is supposed to be coming next. Someone had set it up for me before so that if I put in this code; INSERT INTO u

NoReverseMatch (related to pk) : django

夙愿已清 提交于 2019-12-13 04:33:32
问题 I'd like to get posted-data from a form and display them. I used "{% url uasite1.views.sell_detail sell_detail.pk %}" to extract data according to their pk. However, just [ NoReverseMatch ・・・, Reverse for 'uasite1.views.sell_detail' with arguments '('',)' and keyword arguments '{}' not found.] showed up. What's wrong with my codes? models.py from django.db import models from django.forms import ModelForm class Sell(models.Model): subject = models.CharField(max_length=100) price = models

To get primary and foreign keys right in ERD

心不动则不痛 提交于 2019-12-13 03:58:16
问题 I read my notes and I am now unsure about the keys. My logical diagram alt text http://files.getdropbox.com/u/175564/db/db-11.png This table should be in line with the following physical ERD alt text http://files.getdropbox.com/u/175564/db/db-22.png I have only one foreign key in the table Question . I would like to know should the question-id and question-tag in the table Question-tag-xref , AND question-id and answer in the table Answers be also foreign keys? 回答1: Masi - Logical models don

SQL: Where should the Primary Key be defined

守給你的承諾、 提交于 2019-12-13 03:39:56
问题 I'm creating a database with several sql files 1 file creates the tables. 1 file adds constraints. 1 file drops constraints. The primary is a constraint however I've been told by someone to define your primary key in the table definition but not given a reason why. Is it better to define the primary key as a constraint that can be added and dropped or is it better to do it in the table definition. My current thinking is to do it in the table definition because doing it as a removable

Auto-increment vs composite key

六眼飞鱼酱① 提交于 2019-12-13 03:37:57
问题 I have an additional question related to post: Composite primary keys in databases Please check out the post over there (otherwise I just need to repeat it). Now my question is: If I go for an ID autoincrement as primary key (as I accepted and which allows me to again reference the current table through this key), how can I assure that a combination between User_ID and Admin_ID (both FK's) can only exist once (is unique ) on insert? It is a many-to-many relationship. It could be done in the

Cassandra partial partition key

ⅰ亾dé卋堺 提交于 2019-12-13 02:22:51
问题 CREATE TABLE footable ( column1 text, column2 text, column3 text, column4 text, PRIMARY KEY ((column1, column2)) ) In the example above which I got from Querying Cassandra by a partial partition key, is it possible to use condition on the 1st partition key and select all condition on 2nd partition key? Example cql statement may look like this: select * from footable where column1 = 'name' and column2 ALL; Is there some sort of querying like this in Cassandra? 回答1: is it possible to use

PK on table with (simulated) polymorphic association

一个人想着一个人 提交于 2019-12-13 02:06:11
问题 I am trying to set up the right indices on a table I have just created which contains 4 "polymorphic associations" and a PK ID . The 4 associations allow me not to have to quadruple the number of tables to the addition I am making to the database and should not be modified in this discussion. My question is how should I set up the indices so that I get optimal performance (speed, space not so much) ? None of the 4 keys is candidate for PK. More specifically all 4 are but only one at a time. I

SQL: how to find unused primary key

柔情痞子 提交于 2019-12-12 23:22:58
问题 I've got a table with > 1'000'000 entries; this table is referenced from about 130 other tables. My problem is that a lot of those 1-mio-entries is old and unused. What's the fastet way to find the entries not referenced by any of the other tables? I don't like to do a select * from ( select * from table-a TA minus select * from table-a TA where TA.id in ( select "ID" from ( (select distinct FK-ID "ID" from table-b) union all (select distinct FK-ID "ID" from table-c) ... Is there an easier,

Is it true that a database is 2NF by default if the table only has 1 primary key?

谁说胖子不能爱 提交于 2019-12-12 20:40:52
问题 i.e. there is a table with only 1 primary key (no composite keys). Is it 2NF by default? Assume that it is already 1NF 回答1: http://en.wikipedia.org/wiki/Second_normal_form in your example, PatNo is not a primary key since PatNo may see more than one doctor, or have more than one appNo. 回答2: Loosely speaking, a table is in 2NF if and only if it's in 1NF, and there are no partial key dependencies. That's not quite the same thing as saying a table that has a single-column primary key is in 2NF.