unique-constraint

How to force EclipseLink's @PrivateOwned to perform delete before insert

China☆狼群 提交于 2020-08-02 12:27:04
问题 I have an entity which has @OneToMany private ownership of a collection of another entities. That other entity has some unique constraints over different set of columns. The problem arises when I want to update the main entity (together with changed child entities). EclipseLink does insert before delete, so sometimes, an insertion violates the constraint and throws an exception. Is there a way to force the deletion of child entities before inserting their updated counterparts? 回答1: I know, I

SQLAlchemy Determine If Unique Constraint Exists

北城余情 提交于 2020-07-22 04:08:42
问题 I have a SQLAlchemy model on which I want to run validation. Part of the validation is to ensure a UniqueConstraint exists on a (few) column(s). I know what the columns are. Is there a good way to do this with SQLAlchemy? The underlying database I am using is MySQL. 回答1: You could use SQLalchemy reflection API. In order to get the unique constraints, issue a get_unique_constraints. Primary keys are unique, so you must issue a get_pk_constraint too. table created with: CREATE TABLE user ( id

SQLAlchemy Determine If Unique Constraint Exists

一笑奈何 提交于 2020-07-22 04:08:27
问题 I have a SQLAlchemy model on which I want to run validation. Part of the validation is to ensure a UniqueConstraint exists on a (few) column(s). I know what the columns are. Is there a good way to do this with SQLAlchemy? The underlying database I am using is MySQL. 回答1: You could use SQLalchemy reflection API. In order to get the unique constraints, issue a get_unique_constraints. Primary keys are unique, so you must issue a get_pk_constraint too. table created with: CREATE TABLE user ( id

Django: UNIQUE constraint failed: user.username

我与影子孤独终老i 提交于 2020-05-16 07:45:33
问题 I have a problem using Djangos Default user from django.contrib.auth.models but trying to use it with my custom User model, using from django.contrib.auth.models import AbstractUser . So here is my User model: from django.db import models from django.contrib.auth.models import AbstractUser, UserManager as AbstractUserManager # from django.conf import settings from django_countries.fields import CountryField # https://github.com/SmileyChris/django-countries from django.db.models.signals import

Django: UNIQUE constraint failed: user.username

ぐ巨炮叔叔 提交于 2020-05-16 07:45:06
问题 I have a problem using Djangos Default user from django.contrib.auth.models but trying to use it with my custom User model, using from django.contrib.auth.models import AbstractUser . So here is my User model: from django.db import models from django.contrib.auth.models import AbstractUser, UserManager as AbstractUserManager # from django.conf import settings from django_countries.fields import CountryField # https://github.com/SmileyChris/django-countries from django.db.models.signals import

Conditional unique constraint with multiple fields in oracle db

落花浮王杯 提交于 2020-02-13 08:10:18
问题 I have this table: XPTO_TABLE (id, obj_x, date_x, type_x, status_x) I wanna create a unique constraint that applies to the fields (obj_x, date_x, type_x) only when status_x <> 5 . I have tried to create this one but Oracle says: line 1: ORA-00907: missing right parenthesis CREATE UNIQUE INDEX UN_OBJ_DT_TYPE_STATUS ON XPTO_TABLE( (CASE WHEN STATUS_X <> 5 THEN (OBJ_X, TO_CHAR (DATE_X, 'dd/MM/yyyy'), TYPE_X) ELSE NULL END)); What's the correct syntax ? 回答1: @jamesfrj: it looks like you are

create unique constraints per user

核能气质少年 提交于 2020-01-25 09:50:06
问题 I am building a small app and at this point I am creating the database schema. I use PostgreSQL with Sequel and I have the two migrations: Sequel.migration do change do Sequel::Model.db.run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' create_table :user do String :id, :type => :uuid, :primary_key => true, :default => Sequel.function(:uuid_generate_v4) DateTime :created_at DateTime :updated_at index :id, :unique => true end end end Sequel.migration do change do Sequel::Model.db.run 'CREATE

Django: Model UniqueConstraint gives an error when migrating

我与影子孤独终老i 提交于 2020-01-25 06:57:47
问题 In my Django project the in one of the model I need to use two UniqueConstraint instances. But when I add that and do the migration after running makemigrations it gives an error in the terminal. Model class: class MyDays(models.Model): class Meta: verbose_name = "My Day" verbose_name_plural = "My Days" constraints = [ models.UniqueConstraint(fields=['userid', 'date', 'from'], condition=Q(status=1), name='user_date_from_a'), models.UniqueConstraint(fields=['userid', 'date', 'to'], condition=Q

Rollback Transaction on Trigger ERROR

安稳与你 提交于 2020-01-23 02:38:11
问题 I'm trying to check if the room that is going to be inserted in the system is already rented at that date or not. I've though about counting the rows that match both the room number and the date, and then rolling back the transaction. But I'm getting the following error, even though I have changed the code to raise user-defined exceptions: ERROR: cannot begin/end transactions in PL/pgSQL HINT: Use a BEGIN block with an EXCEPTION clause instead. CONTEXT: PL/pgSQL function "checkRoom"() line 17

How to insert a row and ignore only UNIQUE contraint errors, without using SELECT

感情迁移 提交于 2020-01-16 18:22:12
问题 I have a table with a column that must have UNIQUE values (but it could be also a multiple-column UNIQUE index, the problem is the same). In my PHP script I have to insert a row in that table. I'm searching for a way, not MySQL-specific, to exit the PHP script if there's a problem, and the problem is not a violation of a UNIQUE constraint. To make things more easy I don't want to use a SELECT query before :D Currently I'm doing something like this: try { $stmt = $dbh->prepare($someinsertquery