<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
Field Renaming¶
From version 14.0 to version 15.0, in the module mail
, in the model
mail.activity.type
the html field default_description
has been renamed
into default_note
.
Analysis¶
... ---Fields in module 'mail'--- ... mail / mail.activity.type / default_description (html) : DEL ... mail / mail.activity.type / default_note (html) : NEW
Source Code Differences¶
Version 14.0¶
class MailActivityType(models.Model):<span class="n">_name</span> <span class="o">=</span> <span class="s1">'mail.activity.type'</span> <span class="n">default_description</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Html</span><span class="p">(</span> <span class="n">string</span><span class="o">=</span><span class="s2">"Default Description"</span><span class="p">,</span> <span class="n">translate</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="p">)</span>
See Full V14 Code Source.
Version 15.0¶
class MailActivityType(models.Model):<span class="n">_name</span> <span class="o">=</span> <span class="s1">'mail.activity.type'</span> <span class="n">default_note</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Html</span><span class="p">(</span> <span class="n">string</span><span class="o">=</span><span class="s2">"Default Description"</span><span class="p">,</span> <span class="n">translate</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="p">)</span>
See Full V15 Code Source.
Result without migration script / Expected Result¶
V14 table mail_activity_type
¶
id |
name |
default_description |
---|---|---|
1 |
<p>A description</p> |
|
2 |
Call |
|
3 |
Meeting |
<p>Another description</p> |
V15 table mail_activity_type (Without migration script)¶
id |
name |
default_note |
---|---|---|
1 |
||
2 |
Call |
|
3 |
Meeting |
Problem : the data is lost during them migration process, and the new column is empty.
V15 table mail_activity_type (With migration script)¶
id |
name |
default_note |
---|---|---|
1 |
<p>A description</p> |
|
2 |
Call |
|
3 |
Meeting |
<p>Another description</p> |
Contribution to OpenUpgrade¶
Update upgrade_analysis_work.txt
file¶
Place side by side the two lines that correspond to the change
Mention the operation performed, starting with
# DONE:
---Fields in module 'mail'--- mail / mail.activity.type / default_note (html) : NEW mail / mail.activity.type / default_description (html) : DEL # DONE: pre-migration, rename fields default_description -> default_note
Write migration Script¶
in the pre-migration.py
script add:
from openupgradelib import openupgradedef _rename_fields(env): openupgrade.rename_fields( env, [ ( "mail.activity.type", "mail_activity_type", "default_description", "default_note", ), ] )
@openupgrade.migrate() def migrate(env, version): _rename_fields(env)
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
- Introduction
- Migrating your database
- Community involvement
- Module coverage
- Database analysis
- Migration script development
- OpenUpgrade API
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2012-2021, Odoo Community Association (OCA) / The OpenUpgrade developers.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 5.2.3</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="../_sources/use_cases/field_renaming.rst.txt"
rel="nofollow">Page source</a>
</div>