{"action":"created","issue":{"url":"https://api.github.com/repos/typeorm/typeorm/issues/2181","repository_url":"https://api.github.com/repos/typeorm/typeorm","labels_url":"https://api.github.com/repos/typeorm/typeorm/issues/2181/labels{/name}","comments_url":"https://api.github.com/repos/typeorm/typeorm/issues/2181/comments","events_url":"https://api.github.com/repos/typeorm/typeorm/issues/2181/events","html_url":"https://github.com/typeorm/typeorm/issues/2181","id":324716635,"node_id":"MDU6SXNzdWUzMjQ3MTY2MzU=","number":2181,"title":"Unable to run migrations without a database","user":{"login":"ghost","id":10137,"node_id":"MDQ6VXNlcjEwMTM3","avatar_url":"https://avatars3.githubusercontent.com/u/10137?v=4","gravatar_id":"","url":"https://api.github.com/users/ghost","html_url":"https://github.com/ghost","followers_url":"https://api.github.com/users/ghost/followers","following_url":"https://api.github.com/users/ghost/following{/other_user}","gists_url":"https://api.github.com/users/ghost/gists{/gist_id}","starred_url":"https://api.github.com/users/ghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghost/subscriptions","organizations_url":"https://api.github.com/users/ghost/orgs","repos_url":"https://api.github.com/users/ghost/repos","events_url":"https://api.github.com/users/ghost/events{/privacy}","received_events_url":"https://api.github.com/users/ghost/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-05-20T15:13:26Z","updated_at":"2018-11-29T02:44:49Z","closed_at":"2018-05-23T07:36:14Z","author_association":"NONE","body":"**Issue type:**\r\n\r\n[ ] question\r\n[x] bug report\r\n[x] feature request\r\n[ ] documentation issue\r\n\r\n**Database system/driver:**\r\n\r\n[ ] `cordova`\r\n[ ] `mongodb`\r\n[ ] `mssql`\r\n[x] `mysql` / `mariadb`\r\n[ ] `oracle`\r\n[ ] `postgres`\r\n[ ] `sqlite`\r\n[ ] `sqljs`\r\n[ ] `react-native`\r\n\r\n**TypeORM version:**\r\n\r\n[x] `latest`\r\n[ ] `@next`\r\n[ ] `0.x.x` (or put your version here)\r\n\r\n**Steps to reproduce or a small repository showing the problem:**\r\n1. Create a new migration which creates a database for you.\r\n2. Create a default ormconfig.json without the database option.\r\n3. Run migrations.\r\n\r\n**Expected behavior:**\r\nAll the migrations run successfully.\r\n\r\n**Current behavior:**\r\nMigration failed with error: `ER_NO_DB_ERROR: No database selected`\r\n\r\n**Possible solution:**\r\nRun this query:\r\n```sql\r\nCREATE TABLE `migrations` (`id` int NOT NULL AUTO_INCREMENT, `timestamp` bigint NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB\r\n```\r\nafter first migration was complete.\r\n"},"comment":{"url":"https://api.github.com/repos/typeorm/typeorm/issues/comments/442685994","html_url":"https://github.com/typeorm/typeorm/issues/2181#issuecomment-442685994","issue_url":"https://api.github.com/repos/typeorm/typeorm/issues/2181","id":442685994,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjY4NTk5NA==","user":{"login":"btxtiger","id":15804690,"node_id":"MDQ6VXNlcjE1ODA0Njkw","avatar_url":"https://avatars1.githubusercontent.com/u/15804690?v=4","gravatar_id":"","url":"https://api.github.com/users/btxtiger","html_url":"https://github.com/btxtiger","followers_url":"https://api.github.com/users/btxtiger/followers","following_url":"https://api.github.com/users/btxtiger/following{/other_user}","gists_url":"https://api.github.com/users/btxtiger/gists{/gist_id}","starred_url":"https://api.github.com/users/btxtiger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btxtiger/subscriptions","organizations_url":"https://api.github.com/users/btxtiger/orgs","repos_url":"https://api.github.com/users/btxtiger/repos","events_url":"https://api.github.com/users/btxtiger/events{/privacy}","received_events_url":"https://api.github.com/users/btxtiger/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T02:44:49Z","updated_at":"2018-11-29T02:44:49Z","author_association":"NONE","body":"@pleerock This kind of solution does not work, since typeorm checks if the configured database exists before running any query. Currently there is no way to create the database with typeorm-cli. If you like to run migrations before the application starts, the database needs to already exist.\r\n\r\n```sh\r\n`npx ts-node ./node_modules/.bin/typeorm query \"CREATE SCHEMA IF NOT EXISTS `my_database` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\"`\r\n@xyz.com-err npm ERR! Exit status 1\r\n...\r\nsh: 1: my_database: not found\r\n{ Error: ER_BAD_DB_ERROR: Unknown database 'my_database'\r\n```\r\nEven creating a second config file and not setting the database name fails with message \"database name missing in config\"."}}
{"actor":{"display_login":"btxtiger"}}