I have followed the quickstart setup for Strapi, which as I understand sets up an SQLite Database. I created one collection type (painting) which worked without problems, but whenever I try to add a new one or make changes to the existing one the server does not restart and I receive the following error output in my console:
[2022-05-23 16:53:16.323] error: CREATE TABLE _knex_temp_alter889 (id integer not null primary key autoincrement PRIMARY KEY AUTOINCREMENT NOT NULL, title varchar(255) NULL, artist varchar(255) NULL, created_at datetime NULL, updated_at datetime NULL, published_at datetime NULL, created_by_id integer NULL, updated_by_id integer NULL, CONSTRAINT paintings_created_by_id_fk FOREIGN KEY (created_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_updated_by_id_fk FOREIGN KEY (updated_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_created_by_id_fk FOREIGN KEY (created_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_updated_by_id_fk FOREIGN KEY (updated_by_id) REFERENCES admin_users (id) ON DELETE SET NULL) - table "_knex_temp_alter889" has more than one primary key
SqliteError: CREATE TABLE _knex_temp_alter889 (id integer not null primary key autoincrement PRIMARY KEY AUTOINCREMENT NOT NULL, title varchar(255) NULL, artist varchar(255) NULL, created_at datetime NULL, updated_at datetime NULL, published_at datetime NULL, created_by_id integer NULL, updated_by_id integer NULL, CONSTRAINT paintings_created_by_id_fk FOREIGN KEY (created_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_updated_by_id_fk FOREIGN KEY (updated_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_created_by_id_fk FOREIGN KEY (created_by_id) REFERENCES admin_users (id) ON DELETE SET NULL, CONSTRAINT paintings_updated_by_id_fk FOREIGN KEY (updated_by_id) REFERENCES admin_users (id) ON DELETE SET NULL) - table "_knex_temp_alter889" has more than one primary key
Deleting the changes I made in my content-types files is currently the only way I have of getting the server to run again. How do I fix this?
So, I ended up creating a new project. Problem seems to have been that I added a field named 'ID', which I assume messed everything up because it conflicted with the automatically assigned ID-System.
What is the best way to create entities (with configuration files) from available tables?
imagine that I have a create table query like this:
CREATE TABLE IF NOT EXISTS `mytable`.`task` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NOT NULL,
`description` TINYTEXT NOT NULL,
`due_date` DATETIME NOT NULL,
`attachment` TINYINT(1) NULL,
`project_id` INT NULL,
`user_id` INT NULL,
PRIMARY KEY (`id`),
INDEX `fk_task_1_idx` (`project_id` ASC),
INDEX `fk_task_2_idx` (`user_id` ASC),
CONSTRAINT `fk_task_1`
FOREIGN KEY (`project_id`)
REFERENCES `mava`.`project` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_task_2`
FOREIGN KEY (`user_id`)
REFERENCES `mava`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
is there any way that I can generate task.orm.yml file from this query.
I'm using symfony and doctrine and I have a bunch of tables defined already. So I need to generate Entities from them.
Thanks
Found the answer here:
How to Generate Entities from an Existing Database
Hope it helps someone else
I am using SQL Server 2008 to maintain a database where I have an userAcccounts table where the user details are stored while registering on the website. The userID column is an integer with identity on.
What I have noticed is that somehow, the column is skipping some ids (random number of ids, sometimes it skips 5,11,10 etc), i.e., the ID's are not consecutive. I have a read a similar question here, with a similar issue which suggested
"An identity sequence is incremented any time an insert is attempted
-- this includes a failed or rolled back INSERT"
I have checked my logs for errors, but there were no error during the period when the ids were skipped. Also my insert is not within any transaction for a rollback to happen, because there is no requirement of deleting an account. Also no other tables are involved during the registration
Although this is not a major issue as the ids will be unique nevertheless, what I would like to find out is why this behavior?
Perhaps I am overlooking something.
Are there any other scenarios where this kind of behavior can occur? i.e. the identity column skipping a few ids? Could this be an issue with concurrent access?
here is the table's create script.
CREATE TABLE [dbo].[UserAccounts](
[AccountID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](30) NULL,
[LastName] [varchar](30) NULL,
[Gender] [varchar](10) NULL,
[Email] [varchar](150) NULL,
[EmailVerified] [bit] NULL,
[UserName] [varchar](30) NULL,
[Password] [varchar](50) NULL,
[ProfilePicture] [varchar](150) NULL,
[BackgroundPicture] [varchar](150) NULL,
[DateOfBirth] [smalldatetime] NULL,
[CreateDate] [smalldatetime] NULL,
[LastUpdatedOn] [smalldatetime] NULL,
[Points] [int] NULL,
[CurrentBadge] [varchar](30) NULL,
[FBID] [varchar](50) NULL,
[TwitterID] [varchar](50) NULL,
[Abused] [int] NULL,
[isActive] [bit] NULL,
[AccountTypeID] [int] NULL,
[DateStamp] [timestamp] NOT NULL,
[Location] [varchar](50) NULL,
[About] [varchar](250) NULL,
[UsingBackgroundPicture] [bit] NULL,
CONSTRAINT [PK__UserAcco__349DA5867F60ED59] PRIMARY KEY CLUSTERED
(
[AccountID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Any help in this regard is appreciated? Also if you require any other detail, please let me know.
Thanks
It's impossible to guarantee exact sequentiality of Sequences or IDs, without globally locking the entire database on every transaction -- to prevent any concurrent transactions, which could possibly also ask for an ID.
This would obviously reduce it to effectively a single-user database, and totally destroy performance.
For such reasons, there is explicitly no guarantee of continuous sequentiality.
We have a application where users are entering their time efforts .We have two tables, Production table for entering all production tasks and NonProduction for entering all non production related tasks in the application.We also have a UserInfo table where all the user information is stored like his eCode, Name, Designation,RoleID,ImmediateSupervisor ECode to whom the user is reporting etc.
We are trying to make a sql query in such manner so that any users whose roleid is greater then 1 can drill down and extract the Production and NonProduction information of the users reporting under him but the condition is that the extracted report is of RoleID 1 only.
For example, A Manager RoleID is 4 ,so firstly he drill down and find all the users reporting to him (This info is in ImmediateSupervisor column on UserInfo table)i.e RoleID 3 or RoleID 4, then again we drill down to these Users and extract information who are reporting to them and continue until we drill down up to ROleID 1 and once we drill down to that level, we extract respective users Production and NonProduction details and display in the Report.
Below is the table structure query in Create Table format;
Production Table
CREATE TABLE [dbo].[Production]
(
[ProductionTimeEntryID] [int] IDENTITY(100, 1) NOT NULL,
[CalendarDate] [datetime] NOT NULL,
[UserID] [int] NOT NULL,
[NatureOfWorkID] [int] NOT NULL,
[RegionProjectID] [int] NOT NULL,
[CountyID] [int] NOT NULL,
[WorkTypeID] [int] NOT NULL,
[TaskID] [int] NOT NULL,
[VolumeProcessed] [int] NOT NULL,
[NosOfError] [int] NULL,
[NosOfVolumeAudited] [int] NULL,
[TimeSpent] [varchar](25) NULL,
[Comment] [varchar](250) NULL,
[IsTaskCompleted] [int] NOT NULL,
[isCurrentDayTask] [bit] NOT NULL,
[SupervisorECode] [nvarchar](50) NULL,
CONSTRAINT [PK_Production] PRIMARY KEY CLUSTERED([ProductionTimeEntryID] ASC)
WITH (
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_County] FOREIGN KEY([CountyID])
REFERENCES [dbo].[County] ([CountyID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_County]
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_NatureOfWork] FOREIGN KEY([NatureOfWorkID])
REFERENCES [dbo].[NatureOfWork] ([NatureOfWorkID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_NatureOfWork]
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_RegionAndProjectInfo] FOREIGN KEY([RegionProjectID])
REFERENCES [dbo].[RegionAndProjectInfo] ([RegionProjectID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT
[FK_Production_RegionAndProjectInfo]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_Task] FOREIGN KEY([TaskID])
REFERENCES [dbo].[Task] ([TaskID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_Task]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_USERINFO] FOREIGN KEY([UserID])
REFERENCES [dbo].[USERINFO] ([UserID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_USERINFO]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_WorkType] FOREIGN KEY([WorkTypeID])
REFERENCES [dbo].[WorkType] ([WorkTypeID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_WorkType]
GO
ALTER TABLE [dbo].[Production] ADD DEFAULT((0)) FOR [IsTaskCompleted]
GO
ALTER TABLE [dbo].[Production] ADD DEFAULT((0)) FOR [isCurrentDayTask]
GO
UserInfo Table:
CREATE TABLE [dbo].[USERINFO](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserECode] [nvarchar](50) NOT NULL,
[UserName] [nvarchar](250) NOT NULL,
[CCCode] [nvarchar](50) NULL,
[CCName] [nvarchar](50) NULL,
[Password] [varchar](50) NULL,
[IsFlagEnabled] [bit] NULL,
[IsFirstTimeUserLoggedIn] [bit] NULL,
[EmailAddress] [nvarchar](250) NULL,
[Designation] [varchar](50) NULL,
[ShiftStartTime] [varchar](8) NULL,
[ShiftEndTime] [varchar](8) NULL,
[WeekendShiftStartTime] [varchar](8) NULL,
[WeekendShiftEndTime] [varchar](8) NULL,
[RoleID] [int] NULL,
[ShiftEndFlagStatus] [int] NOT NULL,
[ShiftStartTimeWithTimeStamp] [datetime] NULL,
[ShiftEndTimeWithTimeStamp] [datetime] NULL,
[LoggedInDateTime] [datetime] NULL,
[FirstLoggedInOnthedayflag] [int] NOT NULL,
[ImmediateSupervisor] [nvarchar](50) NULL,
CONSTRAINT [PK_USER] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [RoleID]
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [ShiftEndFlagStatus]
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [FirstLoggedInOnthedayflag]
GO
How to make such query or type of query to incorporate same in my application?
You have a table with a tree structure, the standard way to extract this is to use a recursive cte, something like this:
;with UserTree as
(
select UserECode, UserID
from USERINFO
where UserID = <the managers user-id>
union all
select UserECode, UserID
from UserTree parent
inner join USERINFO child
on child.ImmediateSupervisor = parent.UserECode
)
select * --change this to the specific columns that you need
from UserTree ut
inner join Production p
on p.UserID = ut.UserID
where RoleId = 1
Please note that I haven't managed to test this code, but I'm sure you can fix any minor issues yourself.
More information about recursive cte:s.
I also couldn't help but notice a couple of potential issues with your tree datastructure: ImmediateSupervisor appears to reference UserECode, and I can see two problems in the table structure that you have posted:
No foreign key from ImmediateSupervisor to UserECode. This could result in users that have non-existing supervisors.
UserECode is not unique. This could result in multiple users with the same code, which means multiple supervisors per user, and that will really screw up the recursive cte query.
I don't have the whole picture here, but with what I have I would change the ImmediateSupervisor-column to refer to the PK UserId instead.
with
ProductionCTE(CalendarDate,RoleID,UserID,UserECode,UserName,ImmediateSupervisor,NatureOfWorkName,RegionProjectName,CountyName,WorkTypeName,TaskName,VolumneProcessed,TimeSpent,Comment)
as
(
select P.CalendarDate,U.RoleID,U.UserID,U.UserECode,U.UserName,U.ImmediateSupervisor,N.NatureofWorkName,
R.RegionProjectName,C.Countyname,W.WorktypeName,T.TaskName,P.VolumeProcessed,P.Timespent,P.Comment
from production P inner join NatureOfWork N
on N.NatureofWorkID=P.natureofworkid
inner join dbo.RegionAndProjectInfo R
on R.RegionProjectID=P.RegionProjectID
inner join county C
on C.countyid=P.countyid
inner join worktype W
on W.Worktypeid=P.worktypeID
inner join task T
on T.taskid=P.TaskID
inner join UserInfo U
on U.Userid=P.userid
where P.userid=952
union all
select P.CalendarDate,U.RoleID,U.UserID,U.UserECode,U.UserName,U.ImmediateSupervisor,N.NatureofWorkName,
R.RegionProjectName,C.Countyname,W.WorktypeName,T.TaskName,P.VolumeProcessed,P.Timespent,P.Comment
from production P inner join NatureOfWork N
on N.NatureofWorkID=P.natureofworkid
inner join dbo.RegionAndProjectInfo R
on R.RegionProjectID=P.RegionProjectID
inner join county C
on C.countyid=P.countyid
inner join worktype W
on W.Worktypeid=P.worktypeID
inner join task T
on T.taskid=P.TaskID
inner join UserInfo U
on U.Userid=P.userid
inner join ProductionCTE
on U.ImmediateSupervisor=ProductionCTE.UserECode
)
select distinct CalendarDate,RoleID,UserID,UserECode,UserName,ImmediateSupervisor,NatureOfWorkName,RegionProjectName,CountyName,WorkTypeName,TaskName,VolumneProcessed,TimeSpent,Comment from ProductionCTE order by UserECode
Implementing Recursive CTE fixed the issue and now ia m able to extract the records as per hierarchy.
After creating an index on a rather small table (approx. 700 rows, 10 colums) I started to get
System.Data.SqlClient.SqlException: Timeout expired
The index was clusterd on the primary key.
There are no triggers.
All of these errors occured when doing an update via a stored procedure.
After I removed the index I had no more time-out issues.
Setting CommandTimeout did not help.
Does anybody has an idea why this was happening?
stored procedure (nothing special here)
Update objects set date_last_datacollect=#date_last_datacollect,
date_last_error='',message_last_error='' where objectid = #objectid
Table structure
CREATE TABLE [dbo].[objects](
[id] [int] IDENTITY(1,1) NOT NULL,
[objectid] [nvarchar](50) NULL,
[name] [nvarchar](max) NULL,
[adminid] [nvarchar](50) NULL,
[token] [nvarchar](max) NULL,
[type] [nvarchar](max) NULL,
[date_added] [date] NULL,
[date_last_update] [datetime] NULL,
[date_last_datacollect] [datetime] NULL,
[date_last_error] [datetime] NULL,
[message_last_error] [nvarchar](max) NULL,
[active] [bit] NULL,
[logourl] [nchar](255) NULL
) ON [PRIMARY]
edit:
After viewing my table structure I realize it might be due to the missing primary key?
Have you tried updating statistics on the table?