lamindb_setup.django¶
- lamindb_setup.django(command, package_name=None, **kwargs)¶
Call Django commands.
Examples:
Reset auto-incrementing primary integer ids after a database import:
>>> import lamindb as ln >>> ln.setup.django("sqlsequencereset", "lamindb") BEGIN; SELECT setval(pg_get_serial_sequence('"lamindb_user"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "lamindb_user"; # noqa SELECT setval(pg_get_serial_sequence('"lamindb_storage"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "lamindb_storage"; # noqa COMMIT;
You can then run the SQL output that you’ll see like so:
>>> sql = \"\"\"BEGIN; SELECT setval(pg_get_serial_sequence('"lamindb_user"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "lamindb_user"; # noqa SELECT setval(pg_get_serial_sequence('"lamindb_storage"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "lamindb_storage"; # noqa COMMIT;\"\"\" >>> from django.db import connection >>> with connection.cursor() as cursor: cursor.execute(sql)