Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

databases to models? #138

Closed
Ming-Lei opened this issue Mar 22, 2021 · 5 comments
Closed

databases to models? #138

Ming-Lei opened this issue Mar 22, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@Ming-Lei
Copy link

Is there a command that can generate corresponding models based on the existing database structure
Just like this command of django
python manage.py inspectdb > models.py

@long2ice
Copy link
Member

Yes, see README

@Ming-Lei
Copy link
Author

Encountered some problems during conversion

The table structure is as follows

CREATE TABLE `stock_price` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`code` VARCHAR(50) NULL DEFAULT NULL,
	`date` DATETIME NULL DEFAULT NULL,
	`low` FLOAT NULL DEFAULT NULL,
	`open` FLOAT NULL DEFAULT NULL,
	`close` FLOAT NULL DEFAULT NULL,
	`high` FLOAT NULL DEFAULT NULL,
	PRIMARY KEY (`id`),
	UNIQUE INDEX `code_date` (`code`, `date`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

Execute the following command
aerich inspectdb -t stock_price > models.py

Error message

Traceback (most recent call last):
  File "/home/ming/.local/bin/aerich", line 10, in <module>
    sys.exit(main())
  File "/home/ming/.local/lib/python3.7/site-packages/aerich/cli.py", line 315, in main
    cli()
  File "/home/ming/.local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/ming/.local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/ming/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ming/.local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ming/.local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ming/.local/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/ming/.local/lib/python3.7/site-packages/aerich/cli.py", line 41, in wrapper
    loop.run_until_complete(f(*args, **kwargs))
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/home/ming/.local/lib/python3.7/site-packages/aerich/cli.py", line 310, in inspectdb
    await inspect.inspect()
  File "/home/ming/.local/lib/python3.7/site-packages/aerich/inspectdb.py", line 74, in inspect
    field = self._field_template_mapping[column.data_type].format(
KeyError: 'FLOAT'

@long2ice
Copy link
Member

need fix

@long2ice long2ice added the bug Something isn't working label Mar 22, 2021
long2ice added a commit that referenced this issue Mar 22, 2021
@long2ice
Copy link
Member

Fixed

@AmmarAhmadKhan
Copy link

Fixed

Same Error is occuring on DATE field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants