Unable to create constraint in PostgreSQL

I am trying to create constraint in my rails project. by

add_index :user,[:code,:mobile], unique: true

It’s only creating index in PostgreSQL i have gone and seen in pgAdmin-4, it’s only create index. I have also tried to create constraint on one column using

t.string :txid, index: true, unique: true

But it also create only index.

I required constraint for bulk import some of gem versions are

gem ‘activerecord-import’, ‘~> 1.0’, ‘>= 1.0.6’

gem ‘pg’, ‘~> 1.2’, ‘>= 1.2.3’

ruby ‘2.7.1’

gem ‘rails’, ‘~> 6.0.3’, ‘>=’

PostgreSQL server 12.4

unique: true is not adding constraint in PostgreSQL.

Issue is this when i try to bulk import data in table it’s give me error.


AllTransactions.import data,on_duplicate_key_update: {conflict_target: [:txid],columns: AllTransactions.update_coloums_on_duplicates}


ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification)

I Hope, you can help me in this. Thanks

Github issue link: