Comments (3)
Hi!
The fact that it does not use nulls not distinct
is intentional (as much intentional it can be for the case of default behaviour)
And I am pretty sure it shouldn't be default behaviour
Although adding support would be reasonable, I think it should be done by allowing it as param in tortoise.contrib.postgres.indexes.PostgreSQLIndex
, not by changing behaviour in unique_together
You can contribute this change in PR, or may be I'll be able to take it on somewhere later
I think you can bypass this problem pretty easily by modifying your migration scripts if you have one, or creating index manually if you don't use migration system, as indexes declared on models doesn't affect runtime behaviour
from tortoise-orm.
Hi
that was great idea. by changes at this PR i solved my problem with following approach:
from tortoise... import PostgresUniqueIndex as PUI, SqliteUniqueIndex as SUI
def unique_index_depends_on_current_db_type(fields, null_fields):
"""this function just support sqlite/postgres unique index and nulls will be consider equal"""
is_postgres = envs.db_url.lower().startswith('postgres')
unique_index_class = PUI if is_postgres else SUI
return unique_index_class(fields=fields, nulls='not distinct' if is_postgres else null_fields)
class Customer(BaseModel):
class Meta:
indexes = [unique_index_depends_on_current_db_type(fields=['shop_id','phone_number', 'deleted_at'], null_fields=['deleted_at'])]
from tortoise-orm.
another solution is using nonnull field
class BaseModel(Model):
created_at = fields.DateTimeField(auto_now_add=True)
updated_at = fields.DateTimeField(auto_now=True)
is_deleted = fields.BooleanField(default=False)
from tortoise-orm.
Related Issues (20)
- OperationalError while bulk updating the tortoise model. HOT 1
- [BUG] get_or_create function raises "Object does not exist" HOT 1
- DoesNotExist can be more useful HOT 2
- There is an entry for table "table", but it cannot be referenced from this part of the query HOT 2
- Unable to run unit tests using tortoise-orm initializer() with a postgres database HOT 6
- Is there a django similar scheme to generate model files based on the structure of the existing database python manage.py inspectdb > models.py HOT 1
- [Bug] Failed to set schema for models.Model HOT 1
- Custom generated primary key (Snowflake) ignored, a serial is saved in the backend HOT 2
- Have you considered allowing Tortoise to be independently initialized multiple times in different packages? HOT 3
- Generic relation field HOT 1
- Race condition bug in ConnectionWrapper HOT 1
- I integrated tortoise-orm in FastAPI, but it reported an error when started in debug mode
- KeyError Issue HOT 10
- Problems using `.raw()` instead of `.filter()` HOT 1
- Model.update_or_create should inherit the value of model HOT 5
- Tortoise ORM fails to generate tables for non-default schemas HOT 3
- Can anyone tell me how the distinct() function is going to work?
- IMMEDIATE transaction type in sqlite
- Cannot have Unittest + Postgres + Fastapi combination. It just doesn't work. HOT 15
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 tortoise-orm.