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

[Bug Report] backend的docker容器重启时会重建数据表,导致错误 #39

Closed
JayLiu7319 opened this issue Sep 18, 2023 · 2 comments

Comments

@JayLiu7319
Copy link

环境:Ubuntu 20.04
版本:v0.1.3-4-g28276a7

在重启backend的docker容器时,容器能正常启动,但是检查日志,报错如下:

[16:23:34] INFO     [16:23:34] - INFO - Logger set up with log      logger.py:31
                    level: 10(DEBUG)                                            
INFO:     Started server process [9]
INFO:     Waiting for application startup.
Creating database and tables
           DEBUG    [16:23:34] - DEBUG - Creating database and tables base.py:15
INFO:     Started server process [8]
INFO:     Waiting for application startup.
Creating database and tables
           DEBUG    [16:23:34] - DEBUG - Creating database and tables base.py:15
Error creating database and tables: (pymysql.err.OperationalError) (1050, "Table 'flow' already exists")
[SQL: 
CREATE TABLE flow (
	update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, 
	data JSON, 
	name VARCHAR(255) NOT NULL, 
	user_id INTEGER, 
	description VARCHAR(255), 
	logo VARCHAR(255), 
	status INTEGER, 
	create_time DATETIME, 
	id CHAR(32) NOT NULL, 
	PRIMARY KEY (id), 
	UNIQUE (id)
)

]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
           ERROR    [16:23:34] - ERROR - Error creating database and  base.py:19
                    tables: (pymysql.err.OperationalError) (1050,               
                    "Table 'flow' already exists")                              
                    [SQL:                                                       
                    CREATE TABLE flow (                                         
                            update_time DATETIME NOT NULL DEFAULT               
                    CURRENT_TIMESTAMP,                                          
                            data JSON,                                          
                            name VARCHAR(255) NOT NULL,                         
                            user_id INTEGER,                                    
                            description VARCHAR(255),                           
                            logo VARCHAR(255),                                  
                            status INTEGER,                                     
                            create_time DATETIME,                               
                            id CHAR(32) NOT NULL,                               
                            PRIMARY KEY (id),                                   
                            UNIQUE (id)                                         
                    )                                                           
                                                                                
                    ]                                                           
                    (Background on this error at:                               
                    https://sqlalche.me/e/14/e3q8)                              
ERROR:    Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.10/site-packages/pymysql/cursors.py", line 163, in execute
    result = self._query(query)
  File "/usr/local/lib/python3.10/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 505, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 724, in _read_query_result
    result.read()
  File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 1069, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 676, in _read_packet
    packet.raise_for_error()
  File "/usr/local/lib/python3.10/site-packages/pymysql/protocol.py", line 223, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python3.10/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1050, "Table 'flow' already exists")

mysql容器中已有bisheng的数据库,也有flow这张表,从报错来看,似乎是初始化应用的时候重新创建了表导致冲突

@JayLiu7319 JayLiu7319 changed the title backend的docker容器重启时会重建数据表,导致错误 [Bug Report] backend的docker容器重启时会重建数据表,导致错误 Sep 18, 2023
@yaojin3616
Copy link
Collaborator

初步判断和数据库启动耗时相关。 再做相关启动的优化

@hrfng hrfng closed this as completed Oct 9, 2023
@hrfng hrfng reopened this Oct 9, 2023
@hrfng
Copy link
Contributor

hrfng commented Oct 9, 2023

不同服务启动之间的依赖造成,v0.2版本修复

@hrfng hrfng closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants