Could I add records in ERPNext directly to the DB?

I have a custom doctype that I want to import ~20,000 records to it.
I was thinking maybe I can add the records directly to the DB, would that work? what should I be aware of?

Hi @Mohammad_Johary:

Consider using standard data importing with Excel templates, or this:
https://frappeframework.com/docs/user/en/guides/data/import-large-csv-file

2 Likes

Into which doctype(s) do you want to load the records? That will help answer the question.

While you could potentially load directly into the database, it’s much preferable to do it through the framework, for these reasons:

  • Referential integrity is enforced through the framework (due to Frappe’s design, this is not done at the database level)
  • The proper primary keys (names) will be created, otherwise you’ll need to generate these programmatically and make sure the naming series records in Frappe are properly updated after you’re done
  • Proper field formatting will be enforced, otherwise you’ll need to be careful to make sure compatible values go into their corresponding data types
  • The framework takes care of properly storing dates in their correct time zones, etc
  • If you’re importing child records, the framework handles updating parent-related & idx fields, otherwise you’ll need to do that manually
    There are probably other things I’m missing.

To answer your question: Would it work to add records directly? Maybe. Is it desirable? Probably not. I would try to do imports when possible.

1 Like

It’s a simple doctype that we’ve built, the reason I want to import to the DB directly is the fact that there are ~20000 records that I need.
The doctype does not have a child table, only a link field, date-time field, and some data fields.

Thanks, I’ll try this Import Large Csv File

That could be one of the few times it might be practical to save directly to the database, depending how long the standard import takes, and how familiar you are with Frappe database files.

The main issues you’ll want to watch for in your case is properly formatting the dates/timezones (you can review the results of a test record in a Frappe form to make sure they look right), and setting up the unique names. You can browse around Frappe tables with similar layouts to see how the data is structured.

1 Like