Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlalchemy.exc.CompileError: Can't generate DDL for NullType(); did you forget to specify a type on this Column? #69

Open
8 tasks done
Matthieu-Tinycoaching opened this issue Sep 1, 2021 · 1 comment
Labels
question Further information is requested

Comments

@Matthieu-Tinycoaching
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from datetime import datetime
from typing import Optional, List, Tuple, Dict, Union
from typing_extensions import TypedDict
from sqlmodel import Field, SQLModel, create_engine
from sqlalchemy_utils.functions import database_exists, create_database

class InnerSemanticSearchDict(TypedDict):
    acquis_code: str
    code: str
    level: int
    title: str
    similarity_score: float

class SemanticSearchDict(TypedDict):
    rank: int
    value: InnerSemanticSearchDict

class SemanticSearch(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    id_user: int
    date_time: datetime
    query: str
    clean_query: str
    semantic_search_result: List[SemanticSearchDict]

## sqlite
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"

if not database_exists('postgresql://postgres:postgres@localhost:5432/embeddings_sts_tf'):
    create_database('postgresql://postgres:postgres@localhost:5432/embeddings_sts_tf')

engine = create_engine('postgresql://postgres:postgres@localhost:5432/embeddings_sts_tf', echo=True)

SQLModel.metadata.create_all(engine)

Description

I would like to create a semanticsearch table in the embeddings_sts_tf postgresql database with the 6 fields specified.

But I got the following error code:

2021-09-01 15:35:32,439 INFO sqlalchemy.engine.Engine select version()
2021-09-01 15:35:32,440 INFO sqlalchemy.engine.Engine [raw sql] {}
2021-09-01 15:35:32,440 INFO sqlalchemy.engine.Engine select current_schema()
2021-09-01 15:35:32,440 INFO sqlalchemy.engine.Engine [raw sql] {}
2021-09-01 15:35:32,441 INFO sqlalchemy.engine.Engine show standard_conforming_strings
2021-09-01 15:35:32,441 INFO sqlalchemy.engine.Engine [raw sql] {}
2021-09-01 15:35:32,441 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2021-09-01 15:35:32,442 INFO sqlalchemy.engine.Engine select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2021-09-01 15:35:32,442 INFO sqlalchemy.engine.Engine [generated in 0.00015s] {'name': 'semanticsearch'}
2021-09-01 15:35:32,443 INFO sqlalchemy.engine.Engine ROLLBACK
Traceback (most recent call last):
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 4143, in visit_create_table
    processed = self.process(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 489, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/visitors.py", line 82, in _compiler_dispatch
    return meth(self, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 4177, in visit_create_column
    text = self.get_column_specification(column, first_pk=first_pk)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/base.py", line 2509, in get_column_specification
    colspec += " " + self.dialect.type_compiler.process(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 521, in process
    return type_._compiler_dispatch(self, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/visitors.py", line 82, in _compiler_dispatch
    return meth(self, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 4724, in visit_null
    raise exc.CompileError(
sqlalchemy.exc.CompileError: Can't generate DDL for NullType(); did you forget to specify a type on this Column?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/matthieu/Code/Python/fastapi-graphql/embeddings_sts_tf_postgresql_db.py", line 65, in <module>
    SQLModel.metadata.create_all(engine)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 4740, in create_all
    bind._run_ddl_visitor(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/future/engine.py", line 342, in _run_ddl_visitor
    conn._run_ddl_visitor(visitorcallable, element, **kwargs)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2082, in _run_ddl_visitor
    visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/visitors.py", line 520, in traverse_single
    return meth(obj, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/ddl.py", line 846, in visit_metadata
    self.traverse_single(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/visitors.py", line 520, in traverse_single
    return meth(obj, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/ddl.py", line 890, in visit_table
    self.connection.execute(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/future/engine.py", line 280, in execute
    return self._execute_20(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1583, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/ddl.py", line 77, in _execute_on_connection
    return connection._execute_ddl(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1350, in _execute_ddl
    compiled = ddl.compile(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 489, in compile
    return self._compiler(dialect, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/ddl.py", line 29, in _compiler
    return dialect.ddl_compiler(dialect, self, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 454, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 489, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/visitors.py", line 82, in _compiler_dispatch
    return meth(self, **kw)
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 4153, in visit_create_table
    util.raise_(
  File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
sqlalchemy.exc.CompileError: (in table 'semanticsearch', column 'semantic_search_result'): Can't generate DDL for NullType(); did you forget to specify a type on this Column?

Operating System

Linux

Operating System Details

Ubuntu 18.04 LTS

SQLModel Version

0.0.4

Python Version

3.8.8

Additional Context

No response

@Matthieu-Tinycoaching Matthieu-Tinycoaching added the question Further information is requested label Sep 1, 2021
@lovetoburnswhen
Copy link

Same error with custom types: #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants