SQL errors after modifying a field in the res_user, res_partner or res_company models in odoo
In odoo 12 if you modify a module (and would attempt to update it) which inherits from res_users, res_partner or res_company, then the odoo will stop functioning with an error message similar to this one:
psycopg2.ProgrammingError
psycopg2.ProgrammingError: column res_partner.your_new_field does not exist
LINE 1: ...en" as "ocn_token","res_partner"."date" as "date","res_partn...
In the odoo log file you might see a message like this:
2020-04-21 12:41:35,691 19196 ERROR test odoo.sql_db: bad query: b'SELECT "res_partner"."id" as "id","res_partner"."credit_limit" as "credit_limit","res_partner"."type" as "type","res_partner"."signup_expiration" as "signup_expiration","res_partner"."display_name" as "display_name","res_partner"."commercial_company_name" as "commercial_company_name","res_partner"."state_id" as "state_id","res_partner"."last_time_entries_checked" as "last_time_entries_checked","res_partner"."active" as "active","res_partner"."street" as "street","res_partner"."invoice_warn" as "invoice_warn","res_partner"."company_name" as "company_name","res_partner"."country_id" as "country_id","res_partner"."customer" as "customer","res_partner"."street2" as "street2","res_partner"."calendar_last_notif_ack" as "calendar_last_notif_ack","res_partner"."online_partner_vendor_name" as "online_partner_vendor_name","res_partner"."ref" as "ref","res_partner"."invoice_warn_msg" as "invoice_warn_msg","res_partner"."supplier" as "supplier","res_partner"."industry_id" as "industry_id","res_partner"."zip" as "zip","res_partner"."message_main_attachment_id" as "message_main_attachment_id","res_partner"."partner_gid" as "partner_gid","res_partner"."online_partner_bank_account" as "online_partner_bank_account","res_partner"."lang" as "lang","res_partner"."create_uid" as "create_uid","res_partner"."employee" as "employee","res_partner"."company_id" as "company_id","res_partner"."city" as "city","res_partner"."purchase_warn" as "purchase_warn","res_partner"."sale_warn_msg" as "sale_warn_msg","res_partner"."write_uid" as "write_uid","res_partner"."tz" as "tz","res_partner"."is_company" as "is_company","res_partner"."email" as "email","res_partner"."signup_token" as "signup_token","res_partner"."color" as "color","res_partner"."create_date" as "create_date","res_partner"."commercial_partner_id" as "commercial_partner_id","res_partner"."title" as "title","res_partner"."vat" as "vat","res_partner"."signup_type" as "signup_type","res_partner"."website_id" as "website_id","res_partner"."partner_share" as "partner_share","res_partner"."debit_limit" as "debit_limit","res_partner"."write_date" as "write_date","res_partner"."phone" as "phone","res_partner"."team_id" as "team_id","res_partner"."sale_warn" as "sale_warn","res_partner"."parent_id" as "parent_id","res_partner"."website" as "website","res_partner"."mobile" as "mobile","res_partner"."barcode" as "barcode","res_partner"."ocn_token" as "ocn_token","res_partner"."date" as "date","res_partner"."your_new_field" as "your_new_field","res_partner"."user_id" as "user_id","res_partner"."comment" as "comment","res_partner"."function" as "function","res_partner"."message_bounce" as "message_bounce","res_partner"."additional_info" as "additional_info","res_partner"."purchase_warn_msg" as "purchase_warn_msg","res_partner"."name" as "name" FROM "res_partner" WHERE "res_partner".id IN (3)'
The problem here is that odoo attempts to use the new changed field in the model (those base models are loaded very early in an odoo request), but you haven't had the chance to update your module yet (which would modify the database schema).
The solution is simple, but not straightforward: Either update the module from the command line:
odoo-bin -u your_module -d database_name
...or if you prefer not to do it form the command line you can process as follows:
- Using the version of the module which does not contain the new field (let's say the previous version);
- Restart odoo, check if it works as intended;
- Open Apps, find the module in question; Leave that browser window open;
- Update the module code (files), now it's the time to use the latest copy of your module - which has the new field(s);
- Restart odoo;
- In the browser which you left open in step 3, push the Update button on the module;
Don't forget to update all (other) databases!
Don't know what will come here, let's wait and see... But in the first instance it will be a login box (for myself):
Leave a comment
Comments (if any)