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

Syntax Error arises when NOT NULL and FOREIGN KEY exist in the same column #35

Closed
atsukiwi opened this issue Aug 4, 2022 · 2 comments
Closed

Comments

@atsukiwi
Copy link

atsukiwi commented Aug 4, 2022

Describe the bug
When a column is set as NOT NULL and a foreign key is added, Positional argument cannot appear after keyword arguments error arises in models.py.

To Reproduce
Steps to reproduce the behavior:

Create database.sql.

CREATE TABLE "merchants" (
  "id" int PRIMARY KEY,
  "merchant_name" varchar
);

CREATE TABLE "products" (
  "id" int PRIMARY KEY,
  "merchant_id" int NOT NULL
);

ALTER TABLE "products" ADD FOREIGN KEY ("merchant_id") REFERENCES "merchants" ("id");

Following models.py is produced after create_models.

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


class Merchants(Base):

    __tablename__ = 'merchants'

    id = sa.Column(sa.Integer(), primary_key=True)
    merchant_name = sa.Column(sa.String())


class Products(Base):

    __tablename__ = 'products'

    id = sa.Column(sa.Integer(), primary_key=True)
    merchant_id = sa.Column(sa.Integer(), nullable=False, sa.ForeignKey('merchants.id'))

Expected behavior
In models.py, the last sentence should be like following.

merchant_id = sa.Column(sa.Integer(), sa.ForeignKey('merchants.id'), nullable=False)
@xnuinside
Copy link
Owner

@atsukiwi hi! thanks for reporting the issue, I will work on fix for it

@xnuinside
Copy link
Owner

xnuinside commented Oct 11, 2022

sorry that it is take so much time - fix was released in version 0.12.0 - https://pypi.org/project/omymodels/
tests was added - https://github.com/xnuinside/omymodels/blob/main/tests/functional/generator/test_sqlalchemy_core.py#L122

if will be any new issues - feel free to open the new ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants