-
-
Notifications
You must be signed in to change notification settings - Fork 19k
Open
Labels
BugIO SQLto_sql, read_sql, read_sql_queryto_sql, read_sql, read_sql_queryMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Description
In my database ddl (SQL Server) I have fields which have default values:
my_database_field varchar(255) NOT NULL
DEFAULT 'NVT'
However, when I try to insert data into this table using DataFrame.to_sql() I get the following error:
Cannot insert the value NULL into column 'my_database_field', table 'MYDB.dbo.my_table'; column does not allow nulls. INSERT fails.
Here is the code:
with engine.begin() as conn:
dataframe.to_sql(table_name, conn, index=False, if_exists='append')
The column 'my_database_field' has NaN values:
data['my_database_field']
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
..
4154 NaN
4155 NaN
4156 NaN
4157 NaN
4158 NaN
This seems to be because the to_sql method is replacing NaN values with NULLs (probably how it should be)
I want the option to insert NaN values and have the database use the DEFAULT value defined in the schema instead of inserting NULL directly when using the to_sql method.
Metadata
Metadata
Assignees
Labels
BugIO SQLto_sql, read_sql, read_sql_queryto_sql, read_sql, read_sql_queryMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate