The objects stock.picking.out (Delivery orders) and stock.picking.in (Incomings Shipments), inherits from stock.picking by prototype inheritance, So as to customize the stock.picking.out form view, I added a field on stock.picking, and made it visible juste for stock.picking.out, but now I want to add a sql_constraints unique, to that field, I wrote on stock.picking where the field is decalred :
_sql_constraints = [('bl_uniq','unique(num_bl)','Physical Delivery order number is unique !')].
But this sql constraint doesn't work, is it due to the prototype inheritance ? if yes what is the solution to overcome this issue ?
Hi, 1) Check whether your table already has any null or duplicated value in it. Constraint will not be applied if you have null or duplicated value in column. 2) Check whether your constraint is applied to the table or not. Pgadmin -> Db -> Table -> Constraints -> Your Constraints.
@Dhinesh : I've done a select on "num_bl", the field I want to be unique, it doesn't display any data, while, I am sure I supplied data to this field using the webclient. Is this means that the columns is NULL ? How to access constraints of a table on command line, i'm on ubuntu. @ John: Sorry I don't have enough karma to comment your answer. I performed the sql query that you gave me, but it did'nt work, taking in consideration that the relation is : stock_picking ( the sql table ), the error displayed is : column "stock_picking.num_bl" must appear in the GROUP BY clause or be used in an aggregate function
You should read this:https://www.odoo.com/forum/help-1/question/why-sql-constraints-not-working-39549 especially the comment from Ray CARNES
@Said : Yes, I have alreadu duplicated data for the field num_bl, should I remove all duplicated data and apply the unique constraint ?
Yes, but use it carefully (to avoid any loss of data). The best way to do it is to use a tool like PgAdmin3, and change (or delete) the content of your records. MAKE A BACKUP OF YOUR DATABASE FIRST !!!
MAKE A BACKUP OF YOUR DATABASE FIRST !!!
@ said : I've already done a backup, I'm working on a test database, one last question , I have also empty values for that field num_bl, according to the advice of Dhinesh, it will cause the same problem no ?
I think NO: http://www.postgresql.org/docs/9.0/static/indexes-unique.html and https://www.pgrs.net/2008/01/11/postgresql-allows-duplicate-nulls-in-unique-columns/
Yes you're right, thank you guys : @said @john @dhinesh, it worked fine. the cause was the duplicated data on the unique field, null duplicated values don't affect the work of constraint unique. adding to that I was struggling with the field, That i resolved with john in another topic. Thanks.