You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Change AutoFiled and SmallAutoField to clickhouse Int64, so that id worker can generate value for them.
* `DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'` is no longer a required configuration item.
- In outer join, clickhouse will set missing columns to empty values (0 for number, empty string for text, unix epoch for date/datatime) instead of NULL.
29
29
So Count("book") resolve to 1 in a missing LEFT OUTER JOIN match, not 0.
30
30
In aggregation expression Avg("book__rating", default=2.5), default=2.5 have no effect in a missing match.
31
+
- Clickhouse does not support unique constraint and foreignkey constraint. `ForeignKey`, `ManyToManyField` and `OneToOneField` can be used with clickhouse backend, but no database level constraints will be added, so there could be some consistency problems.
32
+
- Clickhouse does not support transaction. If any exception occurs during migrating, then your clickhouse database will be in an untracked state. Any migration should be full tested in test environment before deployed to production environment.
@@ -143,8 +141,6 @@ automatically route your queries to the right database. In the preceding example
143
141
queries from subclasses of `clickhouse_backend.models.ClickhouseModel` or custom migrations with a `clickhouse` hint key to clickhouse.
144
142
All other queries are routed to the default database (postgresql).
145
143
146
-
`DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'` is required to working with django migration.
147
-
More details will be covered in [DEFAULT_AUTO_FIELD](https://github.com/jayvynl/django-clickhouse-backend/blob/main/docs/Configurations.md#default_auto_field).
148
144
149
145
### Model Definition
150
146
@@ -224,7 +220,7 @@ this operation will generate migration file under apps/migrations/
224
220
then we mirgrate
225
221
226
222
```shell
227
-
$ python manage.py migrate
223
+
$ python manage.py migrate --database clickhouse
228
224
```
229
225
230
226
for the first time run, this operation will generate django_migrations table with create table sql like this
Copy file name to clipboardExpand all lines: docs/Configurations.md
+6-18
Original file line number
Diff line number
Diff line change
@@ -51,9 +51,7 @@ Valid `TEST` keys:
51
51
But this will have a side effect, that is, the clickhouse data of each test case will not be isolated. So in general it is not recommended to use this feature unless you know very well what is the impaction.
52
52
53
53
54
-
### DEFAULT_AUTO_FIELD
55
-
56
-
`DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'` IS REQUIRED TO WORKING WITH DJANGO MIGRATION.
54
+
### Auto Field
57
55
58
56
Django ORM depends heavily on single column primary key, this primary key is a unique identifier of an ORM object.
59
57
All `get``save``delete` actions depend on primary key.
@@ -64,20 +62,10 @@ There is [no unique constraint](https://github.com/ClickHouse/ClickHouse/issues/
64
62
65
63
By default, django will add a field named `id` as auto increasing primary key.
66
64
67
-
- AutoField
68
-
69
-
Mapped to clickhouse Int32 data type. You should generate this unique id yourself.
70
-
71
-
- BigAutoField
72
-
73
-
Mapped to clickhouse Int64 data type. If primary key is not specified when insert data, then `clickhouse_driver.idworker.id_worker` is used to generate this unique id.
74
-
75
-
Default id_worker is an instance of `clickhouse.idworker.snowflake.SnowflakeIDWorker` which implement [twitter snowflake id](https://en.wikipedia.org/wiki/Snowflake_ID).
76
-
If data insertions happen on multiple datacenter, server, process or thread, you should ensure uniqueness of (CLICKHOUSE_WORKER_ID, CLICKHOUSE_DATACENTER_ID) environment variable.
77
-
Because work_id and datacenter_id are 5 bits, they should be an integer between 0 and 31. CLICKHOUSE_WORKER_ID default to 0, CLICKHOUSE_DATACENTER_ID will be generated randomly if not provided.
65
+
Django `AutoField`, `SmallAutoField` and `BigAutoField` ar mapped to clickhouse Int64 data type. If primary key is not specified when insert data, then `clickhouse_driver.idworker.id_worker` is used to generate this unique id.
78
66
79
-
`clickhouse.idworker.snowflake.SnowflakeIDWorker` is not thread safe. You could inherit `clickhouse.idworker.base.BaseIDWorker` and implement one, then set `CLICKHOUSE_ID_WORKER` in `settings.py` to doted import path of your IDWorker instance.
67
+
Default `id_worker` is an instance of `clickhouse.idworker.snowflake.SnowflakeIDWorker` which implement [twitter snowflake id](https://en.wikipedia.org/wiki/Snowflake_ID).
68
+
If data insertions happen on multiple datacenter, server, process or thread, you should ensure uniqueness of (CLICKHOUSE_WORKER_ID, CLICKHOUSE_DATACENTER_ID) environment variable.
69
+
Because work_id and datacenter_id are 5 bits, they should be an integer between 0 and 31. CLICKHOUSE_WORKER_ID default to 0, CLICKHOUSE_DATACENTER_ID will be generated randomly if not provided.
80
70
81
-
Django use a table named `django_migrations` to track migration files. ID field should be BigAutoField, so that IDWorker can generate unique id for you.
82
-
After Django 3.2,a new [config `DEFAULT_AUTO_FIELD`](https://docs.djangoproject.com/en/4.1/releases/3.2/#customizing-type-of-auto-created-primary-keys) is introduced to control field type of default primary key.
83
-
So `DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'` is required if you want to use migrations with django clickhouse backend.
71
+
`clickhouse.idworker.snowflake.SnowflakeIDWorker` is not thread safe. You could inherit `clickhouse.idworker.base.BaseIDWorker` and implement one, then set `CLICKHOUSE_ID_WORKER` in `settings.py` to doted import path of your IDWorker instance.
0 commit comments