tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
841 stars 95 forks source link

databases to models? #138

Closed Ming-Lei closed 3 years ago

Ming-Lei commented 3 years ago

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 commented 3 years ago

Yes, see README

Ming-Lei commented 3 years ago

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 commented 3 years ago

need fix

long2ice commented 3 years ago

Fixed

AmmarAhmadKhan commented 2 years ago

Fixed

Same Error is occuring on DATE field