sqlite-net icon indicating copy to clipboard operation
sqlite-net copied to clipboard

Cannot create a table without columns

Open ghost opened this issue 6 years ago • 10 comments

Hello,

I am getting this error when I am calling the method db.CreateTable<Student>();

I have student class like this : public class Student { [PrimaryKey, AutoIncrement] public int LocalId { get; set; } public string StudentId { get; set; } public string SakshamMitraID { get; set; } public int ID { get; set; } public string Name { get; set; } }

and final code for creating the table this.DBPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AttendanceModel.db"); // Handle when your app starts using (var db = new SQLiteConnection(this.DBPath, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite)) { // Create the tables if they don't exist db.CreateTable<Student>();
}

ghost avatar Aug 19 '19 05:08 ghost

Aren't you suppose to supply some extra info to CreateTable()? I usually use it like connection.CreateTable<Student>();

I don't see how connection.CreateTable(); can just succeed since it has no idea about what kind of table structure you want to create. Did you configure a database/connection to only handle certain objects (like in some other type of database) before calling CreateTable()? I honestly don't think SQLite supports that but asking just in case you didn't show some part of your code.

VaslD avatar Sep 20 '19 10:09 VaslD

this.DBPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AttendanceModel.db");

using (var db = new SQLiteConnection(this.DBPath, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite)) { //Create the tables if they don't exist db.CreateTable<Student>(); }

Below are the tables : public class Student { [PrimaryKey, AutoIncrement] public int LocalId { get; set; } public string StudentId { get; set; } public string SakshamMitraID { get; set; } public int ID { get; set; } public string Name { get; set; } }

On Fri, Sep 20, 2019 at 3:31 PM Yi Ding [email protected] wrote:

Aren't you suppose to supply some extra info to CreateTable()? I usually use it like connection.CreateTable<Student>();

I don't see how connection.CreateTable(); can just succeed since it has no idea about what kind of table structure you want to create. Did you configure a database/connection to only handle certain objects (like in some other type of database) before calling CreateTable()? I honestly don't think SQLite supports that but asking just in case you didn't show some part of your code.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/praeclarum/sqlite-net/issues/863?email_source=notifications&email_token=ACFBIVXJABDBSA5MXBKFDBTQKSNQXA5CNFSM4IMW5TFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7GHCJI#issuecomment-533492005, or mute the thread https://github.com/notifications/unsubscribe-auth/ACFBIVVNZDNDLPY6FVJ7MLLQKSNQXANCNFSM4IMW5TFA .

ghost avatar Sep 21 '19 09:09 ghost

Hi, your code looks fine. Can you report which version you're hitting this on?

praeclarum avatar Sep 21 '19 18:09 praeclarum

sqlite-net-pcl version 1.5.231

On Sat, Sep 21, 2019 at 11:43 PM Frank A. Krueger [email protected] wrote:

Hi, your code looks fine. Can you report which version you're hitting this on?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/praeclarum/sqlite-net/issues/863?email_source=notifications&email_token=ACFBIVUTZL7UVRDBQHTR7UTQKZP5NA5CNFSM4IMW5TFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7IW5HY#issuecomment-533819039, or mute the thread https://github.com/notifications/unsubscribe-auth/ACFBIVTI56HWBCRXBMPP4NLQKZP5NANCNFSM4IMW5TFA .

ghost avatar Sep 24 '19 13:09 ghost

Hi @kumarsachin031 Is that Issue fixed?

Muthutc avatar Apr 23 '20 11:04 Muthutc

I also have the same problem, it still hasn't been solved?

jarsoftSolutions avatar May 05 '20 04:05 jarsoftSolutions

I had this same issue and was able to pinpoint the issue to linker stripping away class properties and therefore in my Unity project I had to add [UnityEngine.Scripting.Preserve] above the class description to prevent this from happening. More information here for other environments https://stackoverflow.com/questions/30059344/table-has-no-public-columns-only-on-real-device

I leave this comment here in case it helps others.

joni-mikkola avatar May 23 '20 05:05 joni-mikkola

Hi there, Is that Issue fixed?

<PackageReference Include="sqlite-net-pcl" Version="1.7.335" /> <PackageReference Include="Xamarin.Forms" Version="4.7.0.968" /> <TargetFramework>netstandard2.1</TargetFramework>

EvgenyPrikhodko avatar Jun 27 '20 00:06 EvgenyPrikhodko

I was going through the same here. Turned out sqlite-net doesn't support private set properties, and I had a table class with all private set props. That was causing the "no properties" exception when trying to create the table.

rafaelagp avatar Dec 28 '20 19:12 rafaelagp

I run into this error, when I have a method in my Table, that uses some query methods, like Single(), directly on a list with children. Example: public string GetTextProjectPartOrderValues(int part_id) { return this.TextProjectParts.Single(tpp => tpp.Id == part_id).OrderValuesCsv; }

HyperactiveGuy avatar Jun 05 '24 12:06 HyperactiveGuy