You can’t create an objectStore in an onsuccess method. You can only do this in a upgradeneeded event.
Quote from docs:
When you create a new database or increase the version number of an existing database (by specifying a higher version number than you did previously, when Opening a database), the
onupgradeneededevent will be triggered. In the handler for this event, you should create the object stores needed for this version of the database
See documentation.