Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

c# insert into postgres using Npgsql - 42P01: relation does not exist

Hi

I'm using npgsql for first time with postgres 11 db

My code is as follows

    cmd = new NpgsqlCommand("INSERT INTO \"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data)	" +
                                                                          "VALUES(@ImeiNumber, @GPSDateTime, @EventId, @Speed, @Latitude, @Longitude, @Heading, @RawData);", con, transactSql)
                                {
                                    CommandType = CommandType.Text
                                };
                                cmd.Parameters.AddWithValue("@ImeiNumber", item.ImeiNumber);
                                cmd.Parameters.AddWithValue("@GPSDateTime", item.GPSDateTime);
                                cmd.Parameters.AddWithValue("@EventId", item.EventId);
                                cmd.Parameters.AddWithValue("@Speed", item.Speed);
                                cmd.Parameters.AddWithValue("@Latitude", item.Latitude);
                                cmd.Parameters.AddWithValue("@Longitude", item.Longitude);
                                cmd.Parameters.AddWithValue("@Heading", item.Heading);
                                cmd.Parameters.AddWithValue("@RawData", item.RawData);
                            
                                cmd.ExecuteNonQuery();

Open in new window


However, I get the error
{"42P01: relation \"tracking_dataa\" does not exist"}

Open in new window


i've tried the following

INSERT INTO \"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO tracking_dataa (imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO \"public\".\"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO public.tracking_dataa (imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

Open in new window


Nothing seems to work, the same error exists

When I browse my DB in Navicat, the table is under the public schema and I can connect fine

What am i doing wrong?
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi webss,


This error indicates that you have not applied migration to the database. Please apply migration.

The table might be there but it could be very well an older table.


Additionally, check if you are connecting the to the right database.


Regards,

Chinmay.

Avatar of websss

ASKER

Thanks
I can see the table and I copied the settings from navicat into my config file (i only have 1 server)

How would I apply a migration?
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial