Comments (11)
I came across this bug today - you're right, it's caused when creating a migration with a ForeignKey
which uses LazyTableReference
.
from piccolo.
Serial is not added to extra_imports when rendering the template. Or is it related to --auto
?
from piccolo.
Ah, interesting - is this on the most recent version of Piccolo?
I wonder under what situations it happens? Were you adding a foreign key to an existing table, or was this a new table?
from piccolo.
I had this problem with one previous version of Piccolo, and now I'm on the latest version.
When I added a foreign key to my forwarded(migrated) User and Tariff tables for Order table.
piccolo migrations new all --auto
...
...
...
β
Finished
It worked for all apps without problems. But when I use the forwards
command to migrate:
piccolo migrations forwards all
SESSION_AUTH
----------------------------------------------------------------
π 2 migrations already complete
π No migrations need to be run
USER
----------------------------------------------------------------
π 4 migrations already complete
π No migrations need to be run
COURSE
----------------------------------------------------------------
π 1 migration already complete
β© 1 migration not yet run
π Running 1 migration:
- 2023-07-14T19:26:53:114807 [forwards]... ok! βοΈ
USERS
----------------------------------------------------------------
π 1 migration already complete
β© 1 migration not yet run
π Running 1 migration:
- 2023-07-14T19:26:53:440473 [forwards]... ok! βοΈ
MY_APP
----------------------------------------------------------------
The command failed.
name 'Serial' is not defined
For a full stack trace, use --trace
from piccolo.
Yeah, I think I saw this on a previous version of Piccolo. The fix is to manually add the import to the migration file:
from piccolo.columns.column_types import Serial
I need to try and figure out if it's a still a problem (i.e. if you create a new migration does it have this problem, or is it just for migrations created in older versions).
So far I've tried adding a foreign key to an existing table, and that included the Serial
import.
from piccolo.
The fix is to manually add the import to the migration file
Yes, I was doing this solution until now. But I thought this issue was a bug because it appeared in my 2-3 projects where different versions of Piccolo were used.
So far I've tried adding a foreign key to an existing table, and that included the Serial import.
So, do I need to migrate my foreign tables first and then add the foreign key? So sorted apps now can't be a help/solution either?
from piccolo.
I had an empty db and empty piccolo_migrations folder (per app) in this try.
piccolo migrations new all --auto
piccolo migrations forwards all
from piccolo.
@dantownsend The problem is with LazyTableReference and was solved when I removed it and imported the model from my other app/tables.py in the tables.py file.
from piccolo.
@hoosnick Ah, that's good to know.
I was trying to find the commit where I thought I'd fixed the Serial
import. This sounds like a new bug then with LazyTableReference
.
from piccolo.
@dantownsend Has the bug been fixed?
from piccolo.
@hoosnick Not yet - I've had a look into it, but haven't created a PR yet.
from piccolo.
Related Issues (20)
- [Enhancement] Exclude `graphlib` from test coverage HOT 1
- Litestar asgi template currently does not work properly
- `Ruff` as a linter for Piccolo HOT 3
- Tweak how `ModelBuilder` creates JSON values
- auto migrations fails when table in schema HOT 3
- Intermittent TypeError in get_sql_value: isinstance() arg 2 must be a type, a tuple of types, or a union HOT 2
- How to use joinοΌ HOT 2
- Implement support for Pydantic v2 HOT 2
- Allow user-defined alternatives to piccolo_app and piccolo_conf files HOT 1
- instance.delete() not work as expected HOT 2
- Properly fix `slotscheck` for Python 3.12
- Type of "create_pydantic_model" is partially unknown (Python 3.11) HOT 3
- Column definition not parsed in class Table HOT 5
- Is it possible to use multiple schemas with SQLiteEngine? HOT 2
- Add columns with `secret=True` parameter to `Table._meta.secret_columns` HOT 1
- `TimestampNow` generates inconsistant values. HOT 4
- Allow SQLite auto migrations
- support in the future for surrealdb? HOT 3
- Pessimistic locking: select for update HOT 2
- Foreign keys with BigSerial not working well HOT 2
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 piccolo.