Comments (3)
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
Fixed check constraint handling with alternate schemas (fixes #3)
from sqlacodegen.
Original comment by YKdvd NA (Bitbucket: YKdvd, GitHub: YKdvd):
It doesn't seem to be the cross-schema bit as such, but something about (at least) an ENUM column in the FK target, even though that target is okay by itself. Here's a test case (the CREATE SCHEMA commands aren't complete):
#!SQL
CREATE SCHEMA IF NOT EXISTS TParent...
CREATE SCHEMA IF NOT EXISTS TChild...
CREATE TABLE `TParent`.`BadTarget` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`userGroup` enum('Guest','Administrator','Modeler','LeadModeler','Layout','LeadLayout','Layout / Animator','Layout / LeadAnimator','Animator','LeadAnimator','Lighter','LeadLighter','LeadLighter / Compositor','LeadLighter / Compositor / Director','Compositor','Lighter / Compositor','LeadCompositor','LeadCompositor / Layout / Animator','Director','TechnicalDirector','TechnicalDirector / Lighter','TechnicalDirector / Lighter / Compositor') NOT NULL DEFAULT 'Guest',
PRIMARY KEY (`id`)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;
CREATE TABLE `TParent`.`GoodTarget` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`dummy` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;
CREATE TABLE `TChild`.`BadSource` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`fkSource` int(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_BadSource_BadTarget` FOREIGN KEY (`fkSource`) REFERENCES `TParent`.`BadTarget` (`id`) ON UPDATE CASCADE,
INDEX `idx_BadSource_fkSource` USING BTREE (fkSource)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;
CREATE TABLE `TChild`.`GoodSource` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`fkSource` int(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_GoodSource_Goodarget` FOREIGN KEY (`fkSource`) REFERENCES `TParent`.`GoodTarget` (`id`) ON UPDATE CASCADE,
INDEX `idx_GoodSource_fkSource` USING BTREE (fkSource)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;
The first run below works okay, and dumps out the Parent tables. The second one works, constraining a TChild table to a TParent table (that has no ENUM). The third one fails, doing the same sort of constraint but to a target table that does have an ENUM. I don't know if it is the length of the ENUM, or just its existence, but it may be a simple thing; I won't have time to dig into your code for awhile.
#!bash
sqlacodegen mysql://dbUser:dbPassword@dbHost/TParent
sqlacodegen --tables GoodSource mysql://dbUser:dbPassword@dbHost/TChild
sqlacodegen --tables BadSource mysql://dbUser:dbPassword@dbHost/TChild
from sqlacodegen.
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
SQLACodegen does not currently handle alternate schemas very well. I'll try to improve on this in the next release.
The test case would still be appreciated.
from sqlacodegen.
Related Issues (20)
- Enable `--options` to be used more than once HOT 6
- Stop double pluralization of names
- In the automatically generated model file, the self-incrementing id field does not have the `autoincrement=true` attribute HOT 5
- codegen.py:390: SAWarning: Cannot correctly sort tables HOT 4
- Code generation for PostgreSQL composite types
- Option --generator only works in pre-release package HOT 3
- fix function name in codegen.py for python v3.11 HOT 1
- Nullable relationships require `Optional`
- Error in Generated SQLAlchemy Model for CHAR Column HOT 2
- Constraints Issues with Oracle HOT 1
- Unable to install `sqlacodegen` due to ioutdated PyPI release HOT 2
- Add support for multiple databases binding
- Entry point documentation
- Enhancement: Add Support for pgvector extension HOT 2
- SQLModel codegen produces syntax errors HOT 4
- Syntax Error in 3.0.0rc3 HOT 5
- No poetry package which supports SQLAlchemy 2.0 HOT 5
- AssertionError: TypeDecorator implementations require a class-level variable 'impl' HOT 14
- sqlalchemy.exc.OperationalError HOT 5
- Database URL is split on & HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlacodegen.