{"record":{"id":"cea8e2af247493e5","repo":"semaphoreui/semaphore","slug":"no-admins-found-in-database-create-a-admin-first","errorCode":null,"errorMessage":"no admins found in database; create a admin first","messagePattern":"no admins found in database; create a admin first","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/cmd/project_import.go","lineNumber":137,"sourceCode":"}\n\nfunc resolveImportUser(store db.Store) (res db.User, err error) {\n\tadmins, err := store.GetAllAdmins()\n\tif err != nil {\n\t\treturn\n\t}\n\n\tif len(admins) > 0 {\n\t\tres = admins[0]\n\t\treturn\n\t}\n\tusers, err := store.GetUsers(db.RetrieveQueryParams{})\n\tif err != nil {\n\t\treturn\n\t}\n\n\tif len(users) == 0 {\n\t\terr = errors.New(\"no admins found in database; create a admin first\")\n\t\treturn\n\t}\n\n\tres = users[0]\n\treturn\n}\n\nfunc importProjectFromFile(path string, projectName string, user db.User, store db.Store) error {\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar backup projectService.BackupFormat\n\tif err := backup.Unmarshal(string(data)); err != nil {\n\t\treturn err\n\t}\n\tif err := backup.Verify(); err != nil {\n\t\treturn err","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/cli/cmd/project_import.go#L119-L155","documentation":"resolveImportUser resolves which user to import a project as; it fetches all users and returns users[0]. When the database contains zero users it sets err to 'no admins found in database; create a admin first', aborting the import because there is no owner to assign the project to.","triggerScenarios":"Running `semaphore project import` (or the import flow calling resolveImportUser) against a fresh/empty database where store.GetUsers returns an empty slice.","commonSituations":"Pointing the import CLI at a brand-new instance before any user registered; importing into a database that was migrated but never had an admin created via `semaphore user add`; wrong config pointing at an empty/other database.","solutions":["Create an admin first: `semaphore user add --login admin --name Admin --email admin@example.com --password ... --admin`","Verify the config points to the intended database (check the users table has rows)","Re-run the import after the user exists"],"exampleFix":"// before\nsemaphore project import project.json   # empty DB\n// after\nsemaphore user add --login admin --name Admin --email admin@example.com --password '***' --admin\nsemaphore project import project.json","handlingStrategy":"validation","validationCode":"if ! semaphore user list | grep -q .; then\n  semaphore user add --login admin --name Admin --email admin@example.com --password \"$PW\" --admin\nfi\nsemaphore project import project.json","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create the admin user on a fresh instance before importing projects","Verify the database config targets the instance you think it does","Script the admin bootstrap as part of environment setup","Check `semaphore user list` non-empty before import runs"],"tags":["cli","database","import","empty-result"],"backgroundTag":"empty-result-set","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}