CSV Export: Add DB Primary Key/ID #2424

Closed
opened 2025-12-29 17:25:58 +01:00 by adam · 2 comments
Owner

Originally created by @anthonyeden on GitHub (Mar 1, 2019).

Environment

  • Python version: 3.7.2
  • NetBox version: 2.5.7

Proposed Functionality

I would like to add an additional column to every CSV export, to include the database primary key for each row of data exported.

I am also proposing to optionally allow an 'id' column header on CSV Imports. If provided, this would trigger a merge/upsert operation on the matching database row - instead of creating a new record.

I am willing to implement this myself and create a pull request.

Use Case

This would make it easier to export all data from a specific model, make some mass changes in spreadsheet software, and then re-import it and merge the data with the existing records in the database.

Database Changes

N/A

External Dependencies

N/A

Originally created by @anthonyeden on GitHub (Mar 1, 2019). ### Environment * Python version: 3.7.2 * NetBox version: 2.5.7 ### Proposed Functionality I would like to add an additional column to every CSV export, to include the database primary key for each row of data exported. I am also proposing to optionally allow an 'id' column header on CSV Imports. If provided, this would trigger a merge/upsert operation on the matching database row - instead of creating a new record. I am willing to implement this myself and create a pull request. ### Use Case This would make it easier to export all data from a specific model, make some mass changes in spreadsheet software, and then re-import it and merge the data with the existing records in the database. ### Database Changes N/A ### External Dependencies N/A
adam closed this issue 2025-12-29 17:25:58 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 1, 2019):

The unique ID assigned to every object is specific to the particular database instance. It is derived from a PostgreSQL sequence and cannot be duplicated or set directly. It's not included in any export because it has no significance outside the local database.

@jeremystretch commented on GitHub (Mar 1, 2019): The unique ID assigned to every object is specific to the particular database instance. It is derived from a PostgreSQL sequence and cannot be duplicated or set directly. It's not included in any export because it has no significance outside the local database.
Author
Owner

@DouglasHeriot commented on GitHub (Mar 4, 2019):

@jeremystretch When importing IP Addresses, the CSV column "device" can be either "Name or ID". IDs are also used in URLs, so they're already exposed to the user. My thought was as they have a purpose for importing relations and for generating URLs, they would be ok and useful to export.

Imagine that IDs were hidden – the issue I had with using device names for importing IP Addresses was that my names weren’t all unique (only unique per site). Would you recommend that device names are globally unique?

As an example, I have:

  • Region: HIL
  • Site: EPI
  • Device Name: Recorder01

Should I instead structure like:

  • Region: HIL
  • Site: EPI
  • Device Name: HIL-EPI-Recorder01
@DouglasHeriot commented on GitHub (Mar 4, 2019): @jeremystretch When importing IP Addresses, the CSV column "device" can be either "Name or ID". IDs are also used in URLs, so they're already exposed to the user. My thought was as they have a purpose for importing relations and for generating URLs, they would be ok and useful to export. Imagine that IDs were hidden – the issue I had with using device names for importing IP Addresses was that my names weren’t all unique (only unique per site). Would you recommend that device names are globally unique? As an example, I have: - **Region:** HIL - **Site:** EPI - **Device Name:** Recorder01 Should I instead structure like: - **Region:** HIL - **Site:** EPI - **Device Name:** HIL-EPI-Recorder01
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2424