Git Product home page Git Product logo

Comments (8)

ksindi avatar ksindi commented on August 30, 2024 1

@ablekh correct that should work. Check that it's version 1.1.6 in __init__.py. I don't think you need to rename but I'm not entirely sure re the issue you're facing.

from flask-sqlacodegen.

ksindi avatar ksindi commented on August 30, 2024 1

@ablekh glad to hear it works! Big thanks to @con-av for the PR. Unfortunately I don't know much about FAB.

from flask-sqlacodegen.

Janzert avatar Janzert commented on August 30, 2024

Given this was the top google result when searching for my own similiar traceback here's what I've found after some digging. The problem seems to result from sqlalchemy changing the type of constraint.columns from a simple list to a ColumnCollection in version 1.0[1]. If all you need is the column name the change to make is simply replacing constraint.columns with constraint.column_keys.

[1] http://docs.sqlalchemy.org/en/rel_1_0/changelog/migration_10.html?highlight=columncollection#foreignkeyconstraint-columns-is-now-a-columncollection

from flask-sqlacodegen.

ksindi avatar ksindi commented on August 30, 2024

Thanks @Janzert. I'm going to mark this as closed.

from flask-sqlacodegen.

ablekh avatar ablekh commented on August 30, 2024

Hello, @Janzert and @ksindi. I experienced the same error as the OP. I followed @Janzert's recommendation above and replaced all instances of constraint.columns with constraint.column_keys in codegen.py (there seem to be no other files affected). Then I tried to reinstall the package via python setup.py install. However, the change results in KeyError = 0 error going away, but another error appearing, as follows:

Traceback (most recent call last):
  File "/usr/local/bin/sqlacodegen", line 9, in <module>
    load_entry_point('sqlacodegen==1.1.5.pre2', 'console_scripts', 'sqlacodegen')()
  File "/usr/local/lib/python2.7/dist-packages/sqlacodegen-1.1.5.pre2-py2.7.egg/sqlacodegen/main.py", line 57, in main
    args.flask, fkcols)
  File "/usr/local/lib/python2.7/dist-packages/sqlacodegen-1.1.5.pre2-py2.7.egg/sqlacodegen/codegen.py", line 597, in __init__
    model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
  File "/usr/local/lib/python2.7/dist-packages/sqlacodegen-1.1.5.pre2-py2.7.egg/sqlacodegen/codegen.py", line 313, in __init__
    for constraint in sorted(table.constraints, key=_get_constraint_sort_key):
  File "/usr/local/lib/python2.7/dist-packages/sqlacodegen-1.1.5.pre2-py2.7.egg/sqlacodegen/codegen.py", line 74, in _get_constraint_sort_key
    return constraint.__class__.__name__[0] + repr(constraint.column_keys)
AttributeError: 'PrimaryKeyConstraint' object has no attribute 'column_keys'

Am I missing something? I would appreciate any help in fixing this issue.

from flask-sqlacodegen.

ksindi avatar ksindi commented on August 30, 2024

@ablekh Just merged @con-av PR which might fix the issue.

from flask-sqlacodegen.

ablekh avatar ablekh commented on August 30, 2024

@ksindi Thank you. How to correctly apply your recent merge: just reinstall the software (git pull origin master, followed by python setup.py install)? If so, do I still need to rename constraint.columns into constraint.column_keys?

from flask-sqlacodegen.

ablekh avatar ablekh commented on August 30, 2024

@ksindi Just tested. I stashed my prior changes (var renaming), updated my local repository, rebuilt and reinstalled the software. Happy to report that it works fine without the prior changes (so I'll just discard them). I was able to successfully auto-generate models - thank you for all your work and help! Now I just hope that the generated models will work well with other modules in my small Flask-AppBuilder (FAB) application, but that's another story... (BTW, do you have any experience with FAB, by any chance?)

from flask-sqlacodegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.