Repository: netbox-community/netbox

Issue:
IPAddress DHCP status is not migrated
<!--
    NOTE: This form is only for reproducible bugs. If you need assistance with
    NetBox installation, or if you have a general question, DO NOT open an
    issue. Instead, post to our mailing list:

        https://groups.google.com/forum/#!forum/netbox-discuss

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report.
-->
### Environment
* Python version:  3.7<!-- Example: 3.5.4 -->
* NetBox version:  2.7.2<!-- Example: 2.5.2 -->

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of NetBox (or the current beta
    release where applicable). Begin with the creation of any necessary
    database objects and call out every operation being performed explicitly.
    If reporting a bug in the REST API, be sure to reconstruct the raw HTTP
    request(s) being made: Don't rely on a wrapper like pynetbox.
-->
### Steps to Reproduce
1. Upgrade from v2.6.3
2. Execute migration
2. Show IPAddress whose status is "DHCP"

<!-- What did you expect to happen? -->
### Expected Behavior
Show the IP correctly

<!-- What happened instead? -->
### Observed Behavior
* The status column/row shows nothing (actually, shows string "5" as Invisible Man)
* IPAddress resource API returns an error: `Key Not Found: '5'`


Discussion:
Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using one of the templates provided [here](https://github.com/digitalocean/netbox/issues/new/choose). For general discussion, questions, or assistance with installation issues, please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss) instead.
To be clear, I have attempted to reproduce this at https://master.netbox.dansheps.com and I am unable to.

Please provide exact steps to reproduce if you wish for us to revisit this, however this seems like it may be a missing step in a upgrade rather then a bug at first glance.
@DanSheps 
Thank you for your quick response. I added some reproducing procedures.

It seems that ba8f324 does not migrate the status "DHCP" to slug.
Alright, this helps now, I will have to go back to 2.6.x and test this out
Just as a quick update, the migration code is in there, so unless something else is happening it should migrate.

Are you fully migrated (can you try running the migrations again?)
> Are you fully migrated

Yes. By running `manage.py migrate`.

https://github.com/netbox-community/netbox/blob/master/netbox/ipam/migrations/0029_3569_ipaddress_fields.py#L4

`IPADDRESS_STATUS_CHOICES` should contain `(5, 'dhcp')`, I think.
The `0029` migration updates IPAddress status to slug, except for DHCP.
> (can you try running the migrations again?)

It is hard to rerun the migration. I have already created a new migration patch and applied it.
(https://github.com/shuichiro-makigaki/netbox/commit/2897232af5c7cf24b50f1a5be4f1d7ba0866ba1d_
As a result, this problem is solved by the patch.
FYI: I see the same problem.  In a system migrated from 2.6 to 2.7:

```
netbox=# select status,count(*) from ipam_ipaddress group by status;
   status   | count
------------+-------
 5          |   134
 deprecated |    18
 active     |  1230
 reserved   |    28
(4 rows)
```

I hadn't noticed until now - thanks for detecting this.

In the GUI, status displays as a white 5 on a white background, which is invisible.  When you hover over it, the background changes to grey so it is visible (just).

Resolving patch:
diff --git a/netbox/ipam/migrations/0029_3569_ipaddress_fields.py b/netbox/ipam/migrations/0029_3569_ipaddress_fields.py
--- a/netbox/ipam/migrations/0029_3569_ipaddress_fields.py
+++ b/netbox/ipam/migrations/0029_3569_ipaddress_fields.py
@@ -2,10 +2,10 @@
 
 
 IPADDRESS_STATUS_CHOICES = (
-    (0, 'container'),
     (1, 'active'),
     (2, 'reserved'),
     (3, 'deprecated'),
+    (5, 'dhcp'),
 )
 
 IPADDRESS_ROLE_CHOICES = (
diff --git a/netbox/ipam/migrations/0034_fix_ipaddress_status_dhcp.py b/netbox/ipam/migrations/0034_fix_ipaddress_status_dhcp.py
new file mode 100644
--- /dev/null
+++ b/netbox/ipam/migrations/0034_fix_ipaddress_status_dhcp.py
@@ -0,0 +1,21 @@
+from django.db import migrations
+
+
+def ipaddress_status_dhcp_to_slug(apps, schema_editor):
+    IPAddress = apps.get_model('ipam', 'IPAddress')
+    IPAddress.objects.filter(status='5').update(status='dhcp')
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ipam', '0033_deterministic_ordering'),
+    ]
+
+    operations = [
+        # Fixes a missed integer substitution from #3569; see bug #4027. The original migration has also been fixed,
+        # so this can be omitted when squashing in the future.
+        migrations.RunPython(
+            code=ipaddress_status_dhcp_to_slug
+        ),
+    ]


Test patch: